GMongo search within an embedded json in an object

86 Views Asked by At

I have the following object:

enter image description here

How can I search for it by only the startDate and endDate fields in the content sub-json?

I tried:

collection.findOne(content: [startDate : givenStartDate, endDate : givenEndDate])

But I guess this would return it only if the entry would have these specific dates but no evalDate, am I right?

How can I query just based on startDate and endDate?

Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

Try like below. You need to use dot operator for sub documents.

collection.findOne("content.startDate" : givenStartDate, "content.endDate" : givenEndDate)