i have 2 table in mongodb. 1 is user and 2 is userbio. so now i want to take first user table and in the table on igid is store and one is object store for filters. and userbio table is store users bio. for ex user table store igid 1 so in userbio table store multiple data for igid 1. so here i want to do filter on that table and store in to final array but how can do that i have no idea any one know then please help me.
Note => In user table Filters object store 4 value. no_of_followers is string and in user bio store followerscount filed to compare. here below i have add one condition in $filter but this condition is not work propare.
This is my user table object =>
{
uid:595bdd5aa6ea2811d48a7802
username:"avc"
target_username:"afd"
igid:209905941
filters{
no_of_followres:"5000"
no_of_following:"5"
externalUrl:true
privacy:false
}
}
This is my data in user bio table =>
{
username : "xyz",
externalUrl : "xyz.com",
fullname : "xyzh",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "test",
externalUrl : "",
fullname : "test",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "re",
externalUrl : "",
fullname : "re",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "qwe",
externalUrl : "",
fullname : "qwe",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "tre",
externalUrl : "",
fullname : "tre",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "fdg",
externalUrl : "",
fullname : "dfg",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
}
{
username : "dcv",
externalUrl : "",
fullname : "dcv",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "ed",
externalUrl : "",
fullname : "ed",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
},
{
username : "yh",
externalUrl : "",
fullname : "yh",
isPrivate: true,
followingCount: 6000,
followerCount : 17,
igid : 209905941
}
my expected o/p =>
var array = [{
username : "xyz",
externalUrl : "xyz.com",
fullname : "xyzh",
isPrivate: false,
followingCount: 49,
followerCount : 17,
igid : 209905941
}]
This my query =>
app.get(prefix + '/GetFollowersInExcel', function (req, res, next) {
var InstaId = 209905941;
user.aggregate([
{ $match: { igid: InstaId } },
{
$lookup: {
from: "userbio",
localField: "igid",
foreignField: "igid",
as: "Data"
}
},
{
$project:
{
res:
{
$filter:
{
input: "$Data",
as: "res",
cond: { $lte: ["$$res.followerCount", '$user.filters.no_of_followers'] } // this is my condition
}
}
}
},
]).exec(function (err, data) {
if (err) {
console.log(err); //res.send(err)
}
else {
console.log("dataExel =>", data)
//res.send(data);
}
});
})