cachegoose icon indicating copy to clipboard operation
cachegoose copied to clipboard

Caching distinct()

Open juona opened this issue 5 years ago • 1 comments

Somewhat similar to https://github.com/boblauer/cachegoose/issues/25.

Distinct returns an array of ObjectIDs rather than an array of Models, which appears to confuse the caching mechanism. Is there any way to fix it easily?

juona avatar Jun 03 '19 11:06 juona

I've just come across this - each ObjectId in the array gets converted to an object of the relevant Model, where the object has keys of numbers from 0 to 23 and the values are the 24 characters of the ObjectId. It also includes any fields Mongoose would include in an object of the Model, e.g. fields defined in the schema with defaults or as an array.

{
  '0': '5',
  '1': 'd',
  '2': 'c',
  '3': '1',
  '4': '5',
  // ...and so on for the whole ObjectId
  someArrayFieldInSchema: [],
  someFieldWithDefault: 0
}

CiaranMn avatar Mar 10 '20 14:03 CiaranMn