Yohanes Lim
Yohanes Lim

Reputation: 95

Nested Query In MongoDb Where Clause

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

Upvotes: 0

Views: 411

Answers (1)

Abdullah Shoaib
Abdullah Shoaib

Reputation: 2095

For request date exists & validate date null:

db.testing.find({"date.validate" : null, "date.request" : {
        $exists : true 
    }   })

Upvotes: 1

Related Questions