Reputation: 57196
How to I exclude certain documents from the search result?
Stream.findOne({
_id: query.id
}, function(err, stream) {
var output = {};
if (err) {
console.log("Error retrieving streams: " + err);
}
if (!stream) {
console.log("No stream found");
}
if (stream) {
console.log("Stream found");
}
});
For instance I want findOne
to skip looking for _id
of 1234
.
Is it possible?
Upvotes: 0
Views: 267
Reputation: 9268
you can try doing this using MongoDB Logical Query operators.
For more information on logical operators , see MongoDB documentation for Logical Query Operators.
Stream.findOne({ $and : [ {_id: query.id } ,{ _id:{ $ne : "1234"} } ]
}, function(err, stream) {
var output = {};
if (err) {
console.log("Error retrieving streams: " + err);
}
if (!stream) {
console.log("No stream found");
}
if (stream) {
console.log("Stream found");
}
});
Upvotes: 1