Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js-mongoose。无法对ObjectId进行查询_Node.js_Mongoose - Fatal编程技术网

Node.js-mongoose。无法对ObjectId进行查询

Node.js-mongoose。无法对ObjectId进行查询,node.js,mongoose,Node.js,Mongoose,这是我第一次在这里问问题。 我使用node.js和mongoose,我有以下三种模式: var CustomerCouponSchema = new Schema({ coupon: { type: Schema.ObjectId, ref: 'Coupon' } }); var CouponSchema = new Schema({ isActive: { type: Boolean, default: false }, supermarket: { type: Sche

这是我第一次在这里问问题。 我使用node.js和mongoose,我有以下三种模式:

var CustomerCouponSchema = new Schema({
    coupon: { type: Schema.ObjectId, ref: 'Coupon' }
});

var CouponSchema = new Schema({
   isActive: { type: Boolean, default: false },
   supermarket: { type: Schema.ObjectId, ref: 'Supermarket' }
}); 

var SupermarketSchema = new Schema({
   name: { type: string }
});
当我尝试执行以下查询时:

//I have a variable named supermarketId which is an ObjectId
CustomerCoupon.find({ isUsed: false })
   .populate({
       path: 'coupon',
       match: {
          supermarket: { $or: [{ $eq: null }, { $eq: supermarketId }] },
          isActive: true,
        }
     }).exec(function(err, data) {
     });
我遇到以下错误:无法将$or与ObjectId一起使用

欢迎提供任何帮助

这可能会解决您的问题。