This is the result of my document after query
players.find().fetch():
{name:'john', sessionIDz:"utFmxmRioDiZdmwGJ"},
{name:'jessica', sessionIDz:"FmwgXvxHZmuAwSzpe"},
{name:'Liz', sessionIDz:"FmwgXvxHZmuAwSzpe"},
{name:'Ericsson', sessionIDz:"FmwgXvxHZmuAwSzpe", Winner: 1},
{name:'Anderson', sessionIDz:"utFmxmRioDiZdmwGJ"}
After query:
players.find( { Winner: { $not: { $gte: 1 } } } ).fetch()
Yeilds:
{name:'Anderson', sessionIDz:"utFmxmRioDiZdmwGJ"},
{name:'john', sessionIDz:"utFmxmRioDiZdmwGJ"},
{name:'jessica', sessionIDz:"FmwgXvxHZmuAwSzpe"},
{name:'Liz', sessionIDz:"FmwgXvxHZmuAwSzpe"}
Which is fine. But now, how do I further narrow down the yield to all documents containing fields sessionIDz:"FmwgXvxHZmuAwSzpe", as illustrated below:
{name:'jessica', sessionIDz:"FmwgXvxHZmuAwSzpe"},
{name:'Liz', sessionIDz:"FmwgXvxHZmuAwSzpe"}
Is there a way I can combine the $not Logical Query Operator in conjunction with other Comparison Query Operators to achieve this yield?.
I have tried the query below, but fail to get the desired result:
player.find({Winner: { $not: { $gte: 1 }}}, {sessionIDz: { $eq:"FmwgXvxHZmuAwSzpe" } }).fetch()
Your help is much appreciated.
You need to include the condition within the same query object. Because the logic NOT greater than or equal to
{ "$not": { "$gte": 1 } }
is just the same as LESS than
{ "$lt": 1 }
your query may be simplified to
player.find({
"Winner": { "$lt": 1 },
"sessionIDz": "FmwgXvxHZmuAwSzpe"
}).fetch()
or if you want to query where the Winner
field does not exist, the query is
player.find({
"Winner": { "$exists": false },
"sessionIDz": "FmwgXvxHZmuAwSzpe"
}).fetch()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments