Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created January 30, 2012 19:57
Show Gist options
  • Save shiawuen/1706310 to your computer and use it in GitHub Desktop.
Save shiawuen/1706310 to your computer and use it in GitHub Desktop.
Was trying to query products based on id passed in, but I got all of the records instead of the one with category id given
var Product = new Schema({
quantity: { type: Number }
, title: { type: String, trim: true }
, category: { type: ObjectId, ref: 'Category' }
})
var Model = db.model('Product', Product);
Product
.statics
.byCategoryId = function(id, next) {
var q = Model.find()
q.where('category', id) // << Works!
// q.where({ category: id }) // << Nope, why?
q.exec(next);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment