javascript - Insert object into multidimensional array in Meteor MongoDB -
I am learning the meteor and I find it difficult to understand MongoDB. I have a collection that has been named as the menu:
id: 123, cat: 'beginning', description: {[item: 'nachos', value: '3.99', desc: 'chips & queso']}
I I want to add another item to that collection:
id: 123, cat: 'starters', Description: {[Item:' nachos', price: '3.99', desc: 'chips and My code looks like this: / P>, which looks like this: ['item:' '4.99', 'descended' Enukaprsrt (_ {id: '123'}, {$ Push: {Description: [[before 'Kailami'}, {value: '4.99'}, {desc: 'fried calamari'}]}});
I also tried to use "update" but I get an error for "non-array $ Push Modfire can not be applied" error
UPDATE Thank you Sindis, you were right and I was able to do this job.
I have created a new collection named Menu 2 in this way.
54, cat: 'Beginner, Description: [[Item:' Nacho 'Price:' 3.99 '}]
Then "Update" has been suggested: / P>
Menu 2.Update ({id: '54 '}, {$ push: {Details: {item:' kelami ', value:' 4.99 '}}});
And I got it!
id: 54, cat: 'beginning', description: [[item: 'nachos', value:' 3.99 '}, {item:' kalami ', value:' 2. 99}}
Not tested but I think it should look more like this:
Menu.upsert ({_ id: '123'}, {$ push: {details: {item: 'calamari', price: '4.99', desc: fried calamari '} }});
Different sections of the object are not required to push you around the object and the update / upstream is already hoping to move the object to an array So there is no need for square brackets.
Comments
Post a Comment