I'm having an issue using the NEDB find()
query structure.
The find()
query below should return all new messages: sent to the email
or the All
group specified and that have not been read or sent by the email
specified.
However, it is returning false positives. For example, the two items in the flat file (below) are returned in the results, despite the fact that the email
IS in the array of the property being evaluated. I am using the $nin
operator and I can't work out what I'm doing wrong? All suggestions welcomed :)
var email = 'anotheraddress@gmail.com';
var message_query = [];
message_query.push({$and: [{to: 'All'}, {'data.readBy': {$nin: [email]}}]});
message_query.push({$and: [{to: email}, {'data.read': {$exists: false}}]});
message
.find({
$and: [
{$not: {from: email}},
{$or: message_query}
]
})
.exec(function (err, results) {
});
Here's a snippet of what the flat file looks like. These two should not be returned, but they are :/
...
{
to: 'All',
toname: 'Some Name',
from: 'someaddress@gmail.com',
fromname: 'Some other Name',
message: 'A message for all...',
timestamp: 1502473320,
imtype: 'msg',
_id: 'K66iP3dZHbYTfGgK',
data:
{ readBy:
[ 'someotheraddress@gmail.com',
'anotheraddress@gmail.com' ] }
},
{
to: 'All',
toname: 'Some Name',
from: 'someoneelse@gmail.com',
fromname: 'Some other Name',
message: 'A message for all...',
timestamp: 1502473420,
imtype: 'msg',
_id: 'K66iP3dZNyNxfGgK',
data:
{ readBy:
[ 'someotheraddress@gmail.com',
'anotheraddress@gmail.com' ] }
}
...
Thanks in advance