我想根据来自两个模型的 route_name 相同的列名称得出价格。怎么做?
第一个模型: -
var routeSchema = mongoose.Schema({
route_name: String,
from_city: String,
to_city : String,
stoppage_point: String,
arrival_time:String,
distance: Number,
journey_date:Date,
approx_time: Number,
status: {
type: Boolean,
default:true,
},
});
var routeModel = module.exports = mongoose.model('routes', routeSchema,"routes");
我想获取数据的模型方法,
module.exports.get_route = function(from_city,to_city,journey_date){
return new Promise(function(resolve,reject){
routeModel.find({'from_city':from_city,'to_city':to_city,'journey_date':journey_date,status:true},"_id route_name from_city to_city stoppage_point distance approx_time arrival_time journey_date", function(err,result){
if(err){
reject(Error(err));
}
resolve(result);
});
})
};
第二个模型:-
var ticketPriceSchema = mongoose.Schema({
route_name: String,
from_city: String,
to_city : String,
price: Number,
});
var ticketPriceModel = module.exports = mongoose.model('ticket', ticketPriceSchema,"ticket");
从这 2 个模型模式中,我还想通过 route_name 从第 2 个模型中得出价格,它是两个模式中的同一列。
结果我也想定价,
_id, route_name, from_city, to_city, stoppage_point, distance, approx_time, arrival_time, journey_date, price