node.js - MongoDB - How to search a value into nested arrays? -


i trying query searches value many sub arrays using mongodb. db schema looks :

user: [ {   name: "somename",  dvd: [      {        collectionname: "actiondvds",        movies: [         {           _id: objectid(x),          mark: 10        },        {           _id: objectid(y),          mark: 8        }      }     ] } ... ] 

i know 3 informations : user.name, dvd.collectioname, movies._id.

for example trying know if there user named "somename", having movie objectid(x) dvd collection named "actiondvds".

i tried query :

user.findone( {   $and:  [     {name: "somename"},     {dvd : {          $elemematch: { name: "actiondvds" }     },     {movies: {          $elemmatch: { _id: objectid(x) }     }   ] }) 

any idea ?

this should it, need nest check movies inside dvd, or it'll match movie inside movie collection;

db.user.findone(     {'name':'somename',       'dvd': {$elemmatch: {'collectionname':'actiondvds',                            'movies': {$elemmatch: { '_id': objectid('x')}}}}}) 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -