How can I combine the $not Logical Query Operator in conjunction with other Comparison Query Operators to get a more specific yield?

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.

Answers


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()

The query json must be the first argument to the find function. You have split the query into 2 separate objects and that is why you are not getting the desired result.

Please try the following:

player.find( { Winner: { $not: { $gte: 1 } }, sessionIDz: "FmwgXvxHZmuAwSzpe" }).fetch()

Also, not greater than or equal to = lesser than. So the following will also achieve your results.

player.find( { Winner: { $lt: 1 }, sessionIDz: "FmwgXvxHZmuAwSzpe" }).fetch()

Need Your Help

Straightforward example of expandable row in GWT DataGrid

java gwt datagrid expandable

I'm trying to pull out the required code from Custom DataGrid Example

Remove posix shared memory when not in use?

c linux shared-memory

Is there any way, linux specific or not, to have posix shared memory segments (obtained with shm_open()) removed when no process is using them. i.e. have them reference counted and have the system ...