0
두 콜렉션 모두에서 코인 id가 동일하게 될 deposit 및 coin_info 콜렉션에서 데이터를 가져 오려고합니다.mongo에서 두 개의 다른 콜렉션에서 일치 레코드를 가져 오는 방법
여기 조회 요약 집계 메서드를 사용하고 있습니다.하지만 결과에 빈 배열이 있습니다.
var mongoose=require('mongoose');
var data = mongoose.Schema({
user_id: { type: String },
coin_key: { type: String }
});
var coin_info = new mongoose.Schema({
_id: { type: String }
coin_code: { type: String }
});
var deposte_model = mongoose.model('deposit', data);
var get_coin_info = mongoose.model('coin_infos', coin_info);
var ccc=deposte_model.aggregate([
{ "$unwind": "$projects" },
{ "$unwind": "$projects.tags" },
{
$lookup:
{
from: "get_coin_info",
localField: "coin_key",
foreignField: "_id",
as: "inventory_docs"
}
},
{ "$unwind": "$inventory_docs" },
{
"$group": {
"_id": null,
"allTags": { "$addToSet": "$inventory_docs" },
"count": { "$sum": 1 }
}
}
]).exec(function(err, results){
console.log(results);
});
VAR의 coin_info는 deposite 참조하면 줄 ({ _id가 \t : 를 mongoose.Schema.Types.ObjectId을}); –
이 올바른 방법일까요? –
네, 그걸 –