node.js - Query Mongoose by passing JSON into Find -


i'm hoping query mongoose this:

users.find({     name: {         first: 'john',         last: 'doe'     } }).exec(function(err, users){     console.log(users); }); 

but looks have format way response:

users.find({     'name.first': 'john',     'name.last': 'doe' }).exec(function(err, users){     console.log(users); }); 

is there way use first method? i'm hoping pass json object directly in without having reformat.

thanks!

you can users.find({ name: { first: 'john', last: 'doe' } } if , if there exact match. means name object contains fields values.

if have:

name: {     first: 'john',     middle: 'fearless',     last: 'doe' } 

then attempting exact match fail. partial match on subdocument have in second example:

users.find({     'name.first': 'john',     'name.last': 'doe' }); 

docs mongodb:


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -