0

How does one implement a logical OR on the same JSON field when querying Mongo from NodeJS?

In particular, I have the following line:

collection.find({"user":req.user.email, "parent._id":0}, function(err, activities){
    if (err) throw err;
    res.json(activities);
});

How could I properly include entries such that "parent":{} is also allowed?

The following gives me an empty array:

collection.find({"user":req.user.email, "parent":{}, "parent._id":0}, function(err, activities){
        if (err) throw err;
        res.json(activities);
    });

1 Answer 1

0

Working code:

collection.find({"user":req.user.email, $or:[{"parent._id":0},{"parent":{}}]}, function(err, activities){
        if (err) throw err;
        res.json(activities);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.