0

i'm quite new and i can't find any query that matches my output.

for ex, i have data look like:

{_id:1, 
  name:a,  
  "date" : {
    "request" : 2020-02-02,
    "validate" : 2021-02-02
}

i'm having a problem using a query to find a data with a request date exists and validate date null.

i tried following query, but it returns all null

db.testing.find({"date.validate" : {$exists:false} })

is there any condition that i can use to manipulate data like

SELECT * FROM testing WHERE request is not null and validate is null

Thanks

1 Answer 1

1

For request date exists & validate date null:

db.testing.find({"date.validate" : null, "date.request" : {
        $exists : true 
    }   })
Sign up to request clarification or add additional context in comments.

4 Comments

Hi abdul, your solution works. i wonder how if i wanted to add name : {$ne : "A"} ? . i encountered error if i add it. thanks
@YohanesLim db.testing.find({"date.validate" : null, "date.request" : { $exists : true },"name":{$ne:"a"}}) should work.
is there any order in using exists and ne and other query operator?
@YohanesLim For these simple queries, I haven't followed any order ever and my queries have returned desired results. Though I'm not aware if there's some order or priority for some other complex forms of queries.

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.