Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- users.aggregate({
- $match:{
- search:/f/
- }},{
- $lookup:
- {from:"users", let:{user:"$_id"}, pipeline:[{
- $match:{
- $expr:{
- $and:[{
- $in:["$$user", "$friend.id"]},{
- $eq:["$_id", ObjectId("5bd22f28f77cfb1f6ce503ca")]
- }]
- }
- }
- },
- {$limit:1},
- {$project:{email:0, password:0}}
- ], as:"is_friend"}},{
- $project:{name:1, search:1, desc:1, color:1, profil:1, banner:1, date:1, friend:1, is_friend:{
- $cond:{
- if:{
- $eq:[{$arrayElemAt:["$is_friend",0]}, undefined]
- },
- then: "false",
- else:"true"
- }
- }
- }
- })
- {
- "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "search" : "flarize",
- "name" : "flarize",
- "email" : "flarize.73@gmail.com",
- "password" : "$2a$10$eYeOtEkEUyD7TFkjKvhZOuSSpvBolkL17TrPHuoHhOT8JrsQR0UKW",
- "color" : 0,
- "profil" : "",
- "banner" : "",
- "desc" : "",
- "date" : 1540501286109,
- "friend" : [
- {
- "id" : ObjectId("5bd19a92da24674fdabd26b6"),
- "date" : 1540676931288
- },
- {
- "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "date" : 1540676931288
- }
- ]
- }
- {
- "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "search" : "flarize",
- "name" : "flarize",
- "color" : 0,
- "profil" : "",
- "banner" : "",
- "desc" : "",
- "date" : 1540501286109,
- "friend" : [
- {
- "id" : ObjectId("5bd19a92da24674fdabd26b6"),
- "date" : 1540666689579
- },
- {
- "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "date" : 1540666689579
- }
- ],
- "is_friends" : "true"
- }
- {
- "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "search" : "flarize",
- "name" : "flarize",
- "color" : 0,
- "profil" : "",
- "banner" : "",
- "desc" : "",
- "date" : 1540501286109,
- "friend" : [
- {
- "id" : ObjectId("5bd19a92da24674fdabd26b6"),
- "date" : 1540666689579
- },
- {
- "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "date" : 1540666689579
- }
- ],
- is_friend : {
- "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "search" : "flarize",
- "name" : "flarize",
- "color" : 0,
- "profil" : "",
- "banner" : "",
- "desc" : "",
- "date" : 1540501286109,
- "friend" : [
- {
- "id" : ObjectId("5bd19a92da24674fdabd26b6"),
- "date" : 1540676931288
- },
- {
- "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
- "date" : 1540676931288
- }
- ]
- }
- }
- users.aggregate({
- $match:{
- search:new RegExp(req.body.search, 'i')
- }},{
- $lookup:
- {from:"users", let:{user:"$_id"}, pipeline:[{
- $match:{
- $expr:{
- $and:[{
- $in:["$$user", "$friend.id"]},{
- $eq:["$_id", new ObjectId(decoded["_id"])]
- }]
- }
- }
- },
- {$limit:1},
- {$project:{email:0, password:0}}
- ], as:"is_friend"}},{
- $project:{name:1, search:1, desc:1, color:1, profil:1, banner:1, date:1, friend:1, is_friend:{
- $cond:{
- if:{
- $eq:[{$arrayElemAt:["$is_friend",0]}, undefined]
- },
- then: "false",
- else:"true"
- }
- }
- }
- })
Add Comment
Please, Sign In to add comment