1

I Use from Mongodb and have a collection like this:

{'name':'vahid','visited':[{id:1,'date':'1223123',noskhe:['a','d','h']]}

I want an update query to add {id:2,'date':'324324',noskhe:['d','n']} to visited array! How I can get this query?

1 Answer 1

4

You need to use $push operator. It will append a new value to the array. Below is the example.

db.collection.update({"name":"vahid"},{$push:{ "visited": {id:2,'date':'324324',noskhe:['d','n']}}})
Sign up to request clarification or add additional context in comments.

2 Comments

Received pymongo.errors.OperationFailure: The field 'field_name' must be an array but is of type object in document
When I try using the push operator (albeit in PyMongo), I get {TypeError}unhashable type: 'dict'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.