0

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!

Community
  • 1
  • 1
Alexandr
  • 708
  • 9
  • 29

1 Answers1

1

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

collection.findOne("content.startDate" : givenStartDate, "content.endDate" : givenEndDate)
Lalit Agarwal
  • 2,354
  • 1
  • 14
  • 18
  • 3
    Try keys in double quotes and see. The query should be fine. From the docs: assert db.languages.findOne(name: 'Groovy').site == 'http://groovy.codehaus.org/' – Lalit Agarwal Mar 17 '15 at 20:15
  • Also, your dates seems to be strings. So make sure your are comparing the correct values. – Lalit Agarwal Mar 17 '15 at 20:18