Aryan
Aryan

Reputation: 2735

how to add a dictionary to array in Mongodb

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?

Upvotes: 1

Views: 3661

Answers (1)

Aravind Yarram
Aravind Yarram

Reputation: 80186

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']}}})

Upvotes: 4

Related Questions