私は関係があるときに、マングースで何かを照会する正しい方法を発見しようとするのに苦労しています。mongooseで参照されているプロパティでフィルターをかける
基本的に私は別のドキュメントに関連するObjectIdを持つ1つのドキュメントを持っています(下記参照)。
しかし、参照のプロパティをフィルタリングしようとすると、何ももう機能しません。 は基本的に、問題は ".where({ "":新しい正規表現(" Recipe.Title *このラインである ")})"
// 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 ** –