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
Post a Comment