我有一个(简化的)模型,基于以下架构:
schema = mongoose.Schema({
foo: { type: String },
bars: [{ type: String }]
});
model = mongoose.model ('model', schema);
我希望创建一个API,返回所有包含以逗号分隔列表形式提供的“bars”的文档。因此,我有以下内容:
exports.findByBars = function (req, res) {
var barsToFind = req.body.bars.split(',');
// find the matching document
};
Mongoose是否提供此API,或者我可以传递查询参数到Model#find以获得此功能?如果仅当文档的bar属性包含
barsToFind
数组中的所有值时才返回该文档。请注意保留HTML标签。