How to find nested data in MongoDB with the following collection:
{
"_id": {
"$oid": "585b998297f53460d5f760e6"
},
"newspaper": {
"playerID": "57bffe76b6a70d6e2a3855b7",
"playerUsername": "dennis",
"player_newspaper": "{\"ID\":\"57bffe76b6a70d6e2a3855b7\",\"Username\":\"Dennis\",\"itemName\":\"Corn\",\"Comment\":\"Jagung Promo\",\"Date\":\"12/27/2016\"}"
}
}
Here is my code:
var datex = new Date();
var dates = datex.getMonth() + '/' + datex.getDate() + '/' + datex.getFullYear();
db.playerNewspaper.remove( {"newspaper.player_newspaper.Date": dates } ) ;
The above code snippet is not working as expected.
In order to insert data, I use the following method:
var currentPlayer = {
"playerID": playerID,
"playerUsername": playerUsername,
"player_newspaper": newspaper
}; // A new player object is created using the input data
playerDataList.insert(
{
"newspaper" : currentPlayer
} // Updating old player data with current player data using the $set mongo modifier
);