P
P
Praud2017-06-01 14:06:57
MongoDB
Praud, 2017-06-01 14:06:57

How to update mongodb?

There is a tree structure

{
    "red": {
         "dynamic_field_time": {
                 "films": {
                       "title": "blabla",
                       "description": "blabla":
                        sessinons: [
                             "18:00",
                             "20:00"    
                        ]
                  }
           },
           ...
    }
}

How to add "dynamic_field_time" directly to red.
db.get().collection('cinemaRooms').findOneAndUpdate(
        { [film.cinemaRoom]: {} }, 
        { 
            $push: { 
                [film.date]: {}
            }
        },
        { new: true },
        (err, docs) => {
            cb(err, docs);
        }
    )

I do as above, but instead of adding the date object directly to red, it adds another object below, without nesting. How to fix ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2017-06-01
@lega

$push adds to the array, and you have *red* - an object, there cannot be duplicate keys in an object

P
Praud, 2017-06-01
@Praud

90036657e0d1404b905d5d6a141bf180.png
There is a problem in the code itself, because if I just change the object to an array, the same picture is obtained

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question