mongoose在田间组合find
是否有可能使用mongoosesearch两个字段的连接。
从Mysql这样的东西:
select * from CARS where concat(make, model) = "<car name>";
说,我有车模式如下:
var carSchema = new mongoose.Schema({ model: String, make: String, }); var Car = mongoose.model('Car', carSchema);
现在是可能的东西:
Car.find( {make + model : <car name>}, function(err, car) { });
你需要使用aggregate()
方法来做到这一点。
Car.aggregate( [ { "$redact": { "$cond": [ { "$eq": [ { "$concat": [ "$make", " ", "$model" ] }, "<car name>" ]}, "$$KEEP", "$$PRUNE" ] }} ], function(err, car) { // Do something } )