How Nested Find MongoDB ? Javascript -


how nested find in mongodb collection data below :

{  "_id": {   "$oid": "585b998297f53460d5f760e6"  },  "newspaper": {   "playerid": "57bffe76b6a70d6e2a3855b7",   "playerusername": "dennis",   "player_newspaper": "{\"id\":\"57bffe76b6a70d6e2a3855b7\",\"username\":\"dennis\",\"itemname\":\"corn\",\"comment\":\"jagung promo\",\"date\":\"12/27/2016\"}"  } } 

my code :

var datex = new date(); var dates = datex.getmonth() + '/' + datex.getdate() + '/' + datex.getfullyear(); db.playernewspaper.remove( {"newspaper.player_newspaper.date": dates } } } ) ; 

this not working.

and

that's how insert data:

var currentplayer = {         "playerid": playerid,         "playerusername": playerusername,         "player_newspaper": newspaper      }; // construct new player data input player data      playerdatalist.insert(     {       "newspaper" : currentplayer     } // uses $set mongo modifier set old player data current player data     ); 

your query looks problem in data. according query condition assume player_newspaper object data shown there player_newspaper string. in query "newspaper.player_newspaper.date": date not found document that's why query not working.

your document structure should like:

{     "_id" : objectid("585b998297f53460d5f760e6"),     "newspaper" : {         "playerid" : "57bffe76b6a70d6e2a3855b7",         "playerusername" : "dennis",         "player_newspaper" : {             "id" : "57bffe76b6a70d6e2a3855b7",             "username" : "dennis",             "itemname" : "corn",             "comment" : "jagung promo",             "date" : "12/27/2016"         }     } } 

then query working fine.

var datex = new date(); var dates = datex.getmonth() + '/' + datex.getdate() + '/' + datex.getfullyear(); db.playernewspaper.remove( {"newspaper.player_newspaper.date": dates } } } ) ; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -