Mongodb:如何更新列表中的单个元素的索引号?

时间:2018-04-21 16:32:24

标签: python mongodb python-3.x

假设我的mongodb数据库看起来像这样:

{'first': ['first_one', 'first_second', 'needed_to_be_updated'], '_id': ObjectId('5adb633bc54d2d035d15169c')}

我希望:

{'first': ['first_one', 'first_second', 'updated_now'], '_id': ObjectId('5adb633bc54d2d035d15169c')}

我想通过index_no更新值,嵌套

data={'first':['first_one','first_second','needed_to_be_updated']}

index_no=2


from pymongo import MongoClient

client = MongoClient()

client = MongoClient('mongodb://localhost:27017/')


db = client.test_database

db = client['new_tagger_one']


posts = db.posts

post_id = posts.insert_one(data).inserted_id

print(posts.find_one())

posts.update_one({'first':??})

0 个答案:

没有答案