Вопрос

I want to store objects like this with mongodb:

{    
    field: 'example',  
    attr: {
        tmp : 'test',
        tmp1 : 'test1'
    }
};

Now I would like to search for the entry which has the property field:'example' and add a field to its attr object. How can I do this in mongojs?

Это было полезно?

Решение

You can add the tmp2:'test2' value into the collection as follows.

db.myObject.update({field:'example'},{$set:{'attr.tmp2':'test2'}})
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top