'Mongo Dart SubDocument Updating and Editing

Hello I have a data like that:

{
"_id":ObjectID(),
"field1":"field1 value",
"group1":{
 {"name": "name1", "favoriteBooks":{"book1","book2"}}, 
 {"name": "name2","favoriteBooks":{"book1","book2"}}, 
    }
}

I want to find document by _id after that in the document's group1, I want to find field by name and insert new value to favoritebooks.

How can I do that ? I searched it and found $push and update methods but I didn't apply these functions to mongo dart.

After 2 days I found the solution :/

Solution

You can search sub document and add new document with $push. But in dart language "$" is special character for string so you should use "\" escape character before the $ like that:

companyColl.update(
          {"_id": Id which we search,
          },
          {"\$push": {"group1": newDocument}}
          )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source