I have a NodeJS script that was working on a server for 6 months, this week I've setup a new server and have installed all updated versions of softwares, including mongojs, nodejs and mongodb, and somehow my code doesn't work anymore.
The part of code:
collect.findOne({$or: [{from_id: enviou, to_id: viu}, {from_id: viu, to_id: enviou}]}, {sort: {$natural: -1}}, function (err, echoData) {
if (err || !echoData) {
console.log("No messages found -rv",err);
} else {
console.log(echoData);
}
});
Gives me the error:
{ [MongoError: Can't canonicalize query: BadValue Projection cannot have a mix of inclusion and exclusion.]
name: 'MongoError',
message: 'Can\'t canonicalize query: BadValue Projection cannot have a mix of inclusion and exclusion.',
'$err': 'Can\'t canonicalize query: BadValue Projection cannot have a mix of inclusion and exclusion.',
code: 17287 }
And this part:
collect.find({$or: [{from_id: de, to_id: para}, {from_id: para, to_id: de}]}, {skip: skipCount, limit: useDbLimit, sort: {time: 1}}, function (err, echoData) {
if (err || !echoData) {
console.log("No messages found -sm",err);
} else {
echoData.forEach(function (returnData) {
console.log(returnData);
});
}
});
Gives me the error:
{ [MongoError: Can't canonicalize query: BadValue Unsupported projection option: sort: { $natural: -1 }]
name: 'MongoError',
message: 'Can\'t canonicalize query: BadValue Unsupported projection option: sort: { $natural: -1 }',
'$err': 'Can\'t canonicalize query: BadValue Unsupported projection option: sort: { $natural: -1 }',
code: 17287 }
I don't have any ideia of how to fix it. It works on my old server, but not on the new with latest mongodb and mongojs. Anyone can help me ?