以下2个系列:门票&股
tickets
Pharma: HEA00004
TxtDtVts: 21112017
ID_REGROUP: 20003000 Int64
Cip7: 787853
Designation: Doliprane
stocks
ICat_id:20003000 Int64
art_st0: 4
和2个架构
var ticketSchema = mongoose.Schema({
NumVts: Number,
Pharma: String,
TxtDtVts: Number,
ID_LGN: Number,
ID_REGROUPEMENT: Number,
});
var Ticket = mongoose.model('Ticket', ticketSchema,'tickets');
var stockSchema = mongoose.Schema({
ICat_ID: Number,
art_st0: Number,
});
var Stock = mongoose.model('Stock', stockSchema,'stocks');
我正在尝试进行“$ lookup”以获得这样的产品库存:
app.get('/join/:pharma/:jour',function(req,res){
var jour = Number(req.params.jour);
Ticket.aggregate([
{"$match":{"Pharma": req.params.pharma}},
{"$match":{"TxtDtVts": jour}},
{ $group : {_id : {Pharma : "$Pharma"}}},
{ $lookup:
{
from: "stocks",
localField: "ID_REGROUP",
foreignField: "ICat_ID",
as: "stock"
}}, ]
,function(err, ticket) {
if (err)
res.send(err);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.json(ticket);
});
});
在响应下方,库存字段仍为空
[
{
"_id":
{
"Pharma": "HEA00004"
},
"stock": []
}
]
为什么查找不适用于此字段?数据类型是否存在问题(int64)?
感谢您提前