我有这样的猫鼬模型模式MongoDB中找到数组的长度超过指定大小
const postSchema = new Schema({
title: String,
headline: [{
kind: String,
id: Schema.Types.ObjectId,
content: String,
relevance: Number,
_id: false
}],
});
我想找到模型,其中headline
数组的长度大于数据库更大的X
我有这个疑问:
const query = {
'headline.kind': 'topic',
'headline.id': topicId,
'headline':{
'$size':{
'$gt': x
}
}
};
但是当我用这个,我得到:
{ 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)
任何人都知道构建此查询的正确方法? (在我的代码中,我只是硬编码x的数字2)。