cachegoose
cachegoose copied to clipboard
Caching distinct()
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?
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
}