0
我有一些困难的时候试图发现正确的方式来查询猫鼬中的东西,当我有一个关系。通过引用属性在猫鼬中筛选
基本上我有一个与ObjectId有关的另一个文档的文档(正如你可以看到以下)。
但是当我尝试过滤引用的属性时,什么都不起作用了。 基本上,问题是这条线 “。凡({ ”Recipe.Title“:新的RegExp(” * “)})”
// const configs
const config = require('./config');
// mongodb setup
const mongoose = require('mongoose');
mongoose.connect(config.database);
var Schema = mongoose.Schema
// recipe schema
const RecipeSchema = mongoose.Schema({
Title: { type: String },
Description: { type: String },
Complaints: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Complaint' }],
});
const Recipe = mongoose.model('Recipe', RecipeSchema);
// complaint schema
const ComplaintSchema = mongoose.Schema({
Recipe : { type: mongoose.Schema.Types.ObjectId, ref: 'Recipe' },
Message: { type: String }
});
const Complaint = mongoose.model('Complaint', ComplaintSchema);
/*
after inserting some items
*/
Complaint
.find()
.populate("Recipe")
.where({ "Recipe.Title": new RegExp("*") }) // this is not working!
.exec((error, items) => {
items.map((item) => {
console.log(item);
});
});
是否有人有解决这个问题的正确方法?
,我就把投诉,但与** **空配方。但实际上我想要的投诉,食谱标题匹配我的正则表达式 –
@EduardoSpaki正确的,这就是为什么我添加了最后的评论关于做或者做其他方式或做聚合。 – Mikey
yeap ...我测试了它,它工作...我刚开始时感到困惑...因为实际上来自**的**是**食谱**(小写)和**。上** T ** –