I have been stuck on this Meteor problem for a while. I am trying to update a nested array within a document in mongodb. However it doesnt seem to update the document at all. Also, there were no error messages emitted which left me confused.
Document structure:
|----_id
|----name
|----members (Array)
|---- [0]
|----history (Array)
|----[0]={type:2,startdate:010304,enddate:120314}
|----[1]={type:1,startdate:140904,enddate:150914}
|----[2]={type:3,startdate:241204,enddate:291214}
|----!!!!!I WANNA ADD THE ENTRY HERE !!!!!!!!!!
|----state
|---- [1]
|----history (Array)
|----[0]={type:2,startdate:010304,enddate:120314}
|----State
This is the code
hisobj = {'type':type, 'startdate':startdate,'enddate':enddate};
parstr = "members["+insertmemberid+"].history";
Groups.update({"_id":Session.get("groupid")},{$addToSet:{parstr:{$each: [hisobj]} } });
Any advice would be greatly appreciated.