I have this Mongoose model schema
const postSchema = new Schema({
title: String,
headline: [{
kind: String,
id: Schema.Types.ObjectId,
content: String,
relevance: Number,
_id: false
}],
});
I want to find models in the database where the headline array has a length greater than x
I have this query:
const query = {
'headline.kind': 'topic',
'headline.id': topicId,
'headline':{
'$size':{
'$gt': x
}
}
};
but when I use this I get:
{ MongooseError: Cast to number failed for value "{ '$gt': 2 }" at path "headline"
at CastError (/home/oleg/WebstormProjects/lectal/api/node_modules/mongoose/lib/error/cast.js:26:11)
anyone know the right way to construct this query? (In my code I just hardcoded the number 2 for x.)