Here is an existing document:
{
"_id": ObjectId("58bfe67c71043e8947d487c7"),
"_class": "com.plash.configurator.model.GmailMailData",
"useremail": "[email protected]",
"threadidslist": [
{
"threadid": "15aac9952c924e6c",
"subject": "dd",
"messagelist": [
{
"messageid": "15aad9c4ebba913c",
"timestamp": "Wed Mar 08 11:09:45 UTC 2017",
"from": "[email protected]",
"body": "<div dir=\"ltr\">ddd</div>\r\n",
"labelid": "RECEIVED"
}
]
}
]
}
The query I am using is:
Update update = new Update();
update.addToSet("messagelist", gm); //gm is the object of messaglist
Criteria criteria = Criteria.where("useremail").is(useremailid)
.and("threadidslist.threadid").is(threadid);
mongoTemplate.updateFirst(Query.query(criteria), update, GmailMailData.class);
This query inserts the object at the top level, but I want the object to be added inside messagelist.
How do I add a new object inside messagelist if useremail and threadid matches?
update.addToSet("threadidslist.$.messagelist", gm)?