I have a mongo collection that looks like this:
{
"_id" : "FfnHWrZuvzBqAk7M5",
"0" : {
"ids" : [
"3",
"1"
]
},
"1" : {
"who" : "3",
"txt" : "aaa",
"time" : "1100"
},
"2" : {
"who" : "1",
"txt" : "bbb",
"time" : "1101"
},
"3" : {
"who" : "1",
"txt" : "ccc",
"time" : "1101"
}
The above is a single document that contains and '_id', the 'ids', then other objects from 1 to eternity with the same set of fields.
I'm trying to update a document by adding the next object (in this example it'd be 4th) like this:
var foo = (some data here);
MNChats.update(
{ _id: Session.get('activeConversationID')},
{ $set: {foo: {who: '3', txt: 'whatever', time: '2100'} } }
);
It works fine, but inserts 'foo' instead of a number stored in the variable.
How can I use a variable in this case?
Or is there any other way I could insert this object automatically under the next number?