mongodbgrailsormgmongodatabase

GMongo search within an embedded json in an object


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!


Solution

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

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