-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update subarray #471
Comments
Hi martiera, db.update({ _id: 'id6', "fruits.name": 'pear' }, { $addToSet: { "fruits.1.size" : "medium" } }, {}, next); I don't know how to help you to discover what is the number of the subelement inside fruits without a get before the update. Check this example: |
Thank you! That way it works. |
how to find fruits.1.size? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, can't insert subarray, maybe I'm doing something wrong. Can you point me how to do in correct way?
Example of data structure:
{ _id: 'id6', fruits: [{name:'orange', size:['small']},{name:‘pear’, size:[]}, {name: ‘apple’, size: ['small', ‘medium']} ] }
db.update({ _id: 'id6', "fruits.name": 'pear' }, { $addToSet: { "fruits.size" : "medium" } }, {}, function(err, numReplaced) {
console.log('Replaced: %s', numReplaced)
})
Console show:
Replaced: 1
db is not updated.
The text was updated successfully, but these errors were encountered: