1

This is my first time asking a question here. I am using node.js and mongoose and I have the following three schemas:

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 }
});

When I am trying to perform the following query:

//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) {
     });

I get the following error: Can't use $or with ObjectId.

Any help would be welcome

nemo
  • 1,675
  • 10
  • 16
  • This may solve your issue. http://stackoverflow.com/questions/7382207/mongooses-find-method-with-or-condition-does-not-work-properly – Mohit Pandey Mar 14 '14 at 09:15

0 Answers0