Created
September 25, 2016 22:47
-
-
Save kitak/4e73471243c02c5cff77d868228efe12 to your computer and use it in GitHub Desktop.
mongoengineのメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Tag.objects(title='Rust')[0] | |
b = Bookmark.objects().first() | |
b.tags = [] | |
b.save() # 初期化 | |
b.tags.append(t) | |
b.tags.append(t) | |
b.save() # タグがダブる | |
b.update(add_to_set__tags=t) # add_to_setを使えばダブらない | |
b.update(add_to_set__tags=t) | |
b.reload() | |
print(list(set(b.tags))) # 重複していてユニークな内容を取り出す場合 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment