javascript - Dot notation on nested objects not in Mongoose schema -


i have mongoose schema providerdata object:

... , providerdata: {}, ... 

and query documents based on ids of objects in providerdata object.

so assumed have use dot notation so:

    user.findone({ provideridstring: providerid }, function(err, user) {...}); 

where

    provideridstring string 'providerdata.facebook.id'     providerid providerdata.facebook id 

however query keeps returning no results though

db.users.find({"providerdata.facebook.id":"thefacebookid"}) 

in mongodb shell returns correct document

am correct assume happening because providerdata.facebook , providerdata.facebook.id not defined in user schema?

does mean have add them schema or there way use dot notation on nested objects not in mongoose schema?

i'm guessing have input like:

var provideridstring = 'providerdata.facebook.id',     facebookid = "thefacebookid"; 

in case use:

var query = {}; query[provoderidstring] = facebookid; 

then:

db.users.find(query); 

and behold! works.

that how construct objects variable names in javascript.


Comments