User.find({
$or:[
{'userSetData.name': { $regex: new RegExp( searchTerm ,'i') }},
{'local.email': { $regex: new RegExp( searchTerm ,'i') }},
{'google.name': { $regex: new RegExp( searchTerm ,'i') }},
{'google.email': { $regex: new RegExp( searchTerm ,'i') }},
{'facebook.name': { $regex: new RegExp( searchTerm ,'i') }},
{'facebook.email': { $regex: new RegExp( searchTerm ,'i') }}
]
}, function(err, doc) {
if( err ){
console.log( err );
}
return doc;
});
The above query fetches any user whose email or name matches the searched criteria. However as expected it returns the entire doc of the user found..
http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/
On the mongodb site they demonstrate the use of the projection
to limit the fields of the doc returned, eg:
db.inventory.find( { type: 'food' }, { item: 1, qty: 1, _id:0 } )
Is it possible to combine an $or from mongoose with the projection
option of mongo, or is post processing the only option?