0

I have been trying to query the Document of posts. The query for the collection is as follows.

db.getCollection('posts').find({ isActive: true, inappropriateReports: { '$exists': true, '$gt': { '$size': 0 } }})

I am able to get the desired results but the issue is as soon as I add the date filter for the query it starts returning the empty array as a response

db.getCollection('tribe-posts').find({ isActive: true,
  createdAt: {
    '$gte': '2021-06-01T00:00:00.000Z',
    '$lte': '2021-07-07T00:00:00.000Z'
  },
  inappropriateReports: { '$exists': true, '$gt': { '$size': 0 } }})

How do I solve this issue as well as have a null check for the collections that doesn't have "inappropriateReports" field?

Thanks in advance

1 Answer 1

2

Assuming you are checking in tribe-posts, try this:

db.getCollection('tribe-posts').find({ isActive: true,
  createdAt: {
    '$gte': new Date('2021-06-01T00:00:00.000Z'),
    '$lte': new Date('2021-07-07T00:00:00.000Z')
  },
  inappropriateReports: { '$exists': true, '$gt': { '$size': 0 } }})

I think passing date as a string will not work.

Sign up to request clarification or add additional context in comments.

Comments

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.