1

suppose my mongodb database looks like this:

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

and i want :

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

I want to update value by index_no , which is nested

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':??})
Aaditya Ura
  • 12,007
  • 7
  • 50
  • 88

0 Answers0