特定のユーザーIDに関連付けられているクーポンのリストを返して、_merchant参照に入力しようとしています。ネゴシエートされた入力クエリ
このクエリは、_merchant refsを正しく入力します。私は追加することができた場合:私は
db.couponModel.find().populate('_merchant').exec(function(err, coupons) {
res.send(coupons);
});
を必要とするか、またはこのクエリは、私が必要とする正確なクーポンを見つけたものを得るでしょう、私のクエリへの
coupon.users.contains(MYUSERIDを)。私が追加することができる場合:
私が必要とするものを得るだろう私のクエリに(_merchant)。
db.userModel.findById(req.params.id).populate('coupons').exec(function(err, user) {
res.send(user.coupons)
});
スキーマ
var userSchema = new Schema({
email: { type: String, required: true , unique: true },
coupons: [{ type: Schema.ObjectId, ref: 'Coupon' }]
});
var couponSchema = new Schema({
_merchant: { type: Schema.ObjectId, ref: 'Merchant', required: true },
couponid: { type: Number, required: true, unique: true },
users: [{ type: Schema.ObjectId, ref: 'User' }]
});
var merchantSchema = new Schema({
name: { type: String, required: true , unique: true }
coupons: [{ type: ObjectId, ref: 'Coupon' }],
});
私が欲しいものを得るためにこれらの2つのクエリの一部のハイブリッドを必要としています。
埋め込みドキュメントの埋め込みドキュメントには、まだ埋め込まれていないと思われます。 https://github.com/LearnBoost/mongoose/issues/601#issuecomment-6520568 – idursun
を参照してください。数日前のリリースでサポートされていると思いますが、まだドキュメントはありません。それを回避するためのハックおそらく$を使用していますか? – user1071182
https://github.com/LearnBoost/mongoose/pull/1292 – user1071182