Created
June 8, 2011 23:28
-
-
Save bnoguchi/1015715 to your computer and use it in GitHub Desktop.
Correct example for GH-247
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example works also works if you swap the commented lines into the code, and comment | |
// the corresponding uncommented lines. | |
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema ; | |
mongoose.connect('mongodb://localhost/test'); | |
var Item = new Schema({ | |
cat_id: Number | |
, produces: {type: Schema.Types.Mixed, default: {}} // Mixed | |
// , produces: { | |
// cpu_frequency: Number | |
// } | |
}); | |
Item = mongoose.model('Item', Item); | |
Item.create({ | |
cat_id: 2, | |
// produces: { cpu_frequency: 100 } | |
'produces.cpu_frequency': 100 | |
}, { | |
cat_id: 2, | |
// produces: { cpu_frequency: 3800 } | |
'produces.cpu_frequency': 3799 | |
}, { | |
cat_id: 2, | |
// produces: { cpu_frequency: 3801 } | |
'produces.cpu_frequency': 3800 | |
}, function (err) { | |
Item | |
.where('cat_id', 2) | |
.where('produces.cpu_frequency').gte(90).lte(3800) | |
.limit(20) | |
.find( function (err, items) { | |
console.log(items); | |
items = items.map( function (item) { | |
return item.toObject(); | |
}); | |
mongoose.disconnect(); | |
}); | |
}); | |
// Output should be | |
// [ { produces: { cpu_frequency: 3800 }, | |
// cat_id: 2, | |
// _id: 4df005d5ec7b5bf702000001 }, | |
// { produces: { cpu_frequency: 3800 }, | |
// cat_id: 2, | |
// _id: 4df005d5ec7b5bf702000002 }, | |
// { produces: { cpu_frequency: 3800 }, | |
// cat_id: 2, | |
// _id: 4df005d5ec7b5bf702000003 } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment