Im trying to query mongo, and query's based on a specific field, such as a username or country, it returns only that match. I can get the data i want on a get request, but whenever I try to query by specific field it breaks. It will return this error.
my query string : localhost:4002/users?firstName=Mark
err: MongoError: Can't canonicalize query: BadValue Unsupported projection option: firstName: { $match: "Mark" }
app.get('/users', (req,res) => {
co(function*(){
var dbSocial = yield MongoClient.connect(dbSocialUrl);
let query = {
firstName:1,
lastName:1,
createDT:1,
"_mailAddress.country":1,
ownerId:1,
userName:1
}
//
if (req.query.firstName) {
query["firstName"] = {
$match: req.query.firstName || '',
}
}
console.log('query',query);
//get users
var users = yield dbSocial
.collection('user')
.find({},(query))
.limit(100)
.toArray();
})