[英]lookup not working mongodb
my views data : 我的观看数据:
{
"msg": "Recently Viewed Experiences",
"data": [
{
"_id": "5aafce9ea33f68234466b790",
"userId": "5aaf58dccf409c770353b5d1",
"expId": "5aabc6d7bdd1940858284b09",
"__v": 0,
"created": "2018-03-19T14:52:14.154Z"
},
{
"_id": "5ab09cec046e802b9c0599fc",
"userId": "5aaf58dccf409c770353b5d1",
"expId": "5aafdc7abea7fe08c778885d",
"__v": 0,
"created": "2018-03-20T05:32:28.436Z"
}
]
}
my find functon : 我发现功能:
function getViewedExperiences(){
return new Promise(function(resolve,reject){
Views.find(
[{userId: req.userId},{$lookup: {from: "experiences",localField: "_id",foreignField: "expId",as: "experience"}}
],function(err,result){
if(err){
reject(err);
}else{
resolve(result);
}
});
});
}
my experience : 我的经验 :
{
"_id": "5aabc6d7bdd1940858284b09",
"name": "My First Experience",
"subtitle": "Experience Subtitle ",
"description": "Welcome to a soulful experience of vacationing in India, the cradle of ancient civilization with rich cultural heritage.",
"whatwedo": "Experience the sights and sounds of its amazing diversity that is embedded in its geography, people and their cultures. Explore the gifts of nature and the timeless marks",
"whocancome": "Any on can come\n",
"whatweprovide": "Experience the sights and sounds of its amazing diversity that is embedded in its geography",
"cancellationPolicy": "Cancellation Policy. We require 14 days cancellation notice prior to your scheduled arrival, otherwise we will charge you cancellation fee as below. 10% of your total amount will be charged if you do not notify us about your cancellation or any changes by 14 to 8 days before your scheduled arrival",
"hostPhone": "400",
"geoLocation": [
28.628454,
28.628454
],
"price": 4000,
"__v": 0,
"dateCreated": "2018-03-20T05:32:42.876Z",
"rating": 5,
"currency": "Pound",
"address": "G70, Sector 63 Noida",
"status": "live",
"images": [
"[\"https://thumbnails.trvl-media.com/59v7eyda1z0_UsX4oB0MuP8b8Ao=/a.travel-assets.com/flex/flexmanager/images/2018/02/27/TVLY_PromoCode_TRIPTIME_lpad_532x299_20180131.jpg\"]"
]
}
I need to lookup data from other experiences documents in my views document there is a foreign field expId which is _id in my experiences document i want to fetch data from experiences. 我需要从我的视图文档中的其他体验文档中查找数据,在我的体验文档中我想从体验中获取数据时有一个外地字段expId ,它是_id 。 i used $lookup but its not working for me
我用$ lookup但对我不起作用
function getViewedExperiences(){
return new Promise(function(resolve,reject){
Views.find(
{userId: req.userId}
).populate({
path:'expId',
model:Experiences
}).exec(function(err,result){
if(err){
reject(err);
}else{
resolve(result);
}
});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.