0

I have a mongoose model that has a field called timeLimit which is an Object

timeLimit: {
  type: Object,
  // of: Date,
},

If I try to find documents in this collection using the following query

const docs = await Model.find({
    'timeLimit.end': {
      $gt: moment().utc(),
    },
  });

I get no result, despite the fact that there are valid values to be returned. However, if I change the field in the model to match a Map of Dates...

timeLimit: {
  type: Map,
  of: Date,
},

The query returns the valid values of this query.

My question is, why is the query invalid when using the Object mongoose type if MongoDB doesn't even have the Map type, only the Object type?

Types shown in Mongo Compass

kaiofreis
  • 35
  • 1
  • 4
  • Does this answer your question? [Object type in mongoose](https://stackoverflow.com/questions/42019679/object-type-in-mongoose) – Valijon Jan 31 '20 at 19:33
  • Not quite. It does not cover why fields in an object can't be indexed, but fields in a Map can. – kaiofreis Feb 02 '20 at 22:26

0 Answers0