[SERVER-32949] lookup between local (single)value in every object and foreign (single) value and i got an empty array Created: 29/Jan/18  Updated: 28/Feb/18  Resolved: 05/Feb/18

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 3.6.1
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: nithin Assignee: Bruce Lucas (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File tasks.png     PNG File userdata.png    
Participants:

 Description   

db.Tasks.aggregate([ {
$lookup:

{ from: "Userdata", localField: "customer_id", foreignField: "_id", as: "userdetails" }

} ]

here i get the empty array of userdetails .
please check i gave the response below.
response:
[

{ "_id": "5a6ecde19f3a0d31f4cd5b5e", "executive_id": "5a6ec6879a3e3406f8f7d70b", "customer_id": "5a5495b1a03790158019a7d5", "task_completed": false, "__v": 0, "userdeatails": [] }

,

{ "_id": "5a6ecdf29f3a0d31f4cd5b5f", "executive_id": "5a6ec6879a3e3406f8f7d70b", "customer_id": "5a5495b1a03790158019a7d5", "task_completed": false, "__v": 0, "userdeatails": [] }

,

{ "_id": "5a6ece0d9f3a0d31f4cd5b60", "executive_id": "5a6ec6879a3e3406f8f7d70b", "customer_id": "5a67055d611e836db9078ca3", "task_completed": false, "__v": 0, "userdeatails": [] }

,

{ "_id": "5a6ed8829f3a0d31f4cd5b61", "executive_id": "5a6ec822c2eee725f8282b3c", "customer_id": "5a67055d611e836db9078ca3", "task_completed": false, "__v": 0, "userdeatails": [] }

]



 Comments   
Comment by nithin [ 31/Jan/18 ]

k thank you

Comment by Bruce Lucas (Inactive) [ 29/Jan/18 ]

Hi,

The empty userdetails array indicates that there are no documents in Userdata with an _id matching that customer_id. To check whether this is correct please execute the following:

    result = db.Tasks.aggregate([{
        $lookup: {
            from: "Userdata",
            localField: "customer_id",
            foreignField: "_id",
            as: "userdetails" }
    }]).next()
    printjson(result)
 
    check = db.Userdata.findOne({_id: result.customer_id})
    printjson(check)

If this shows that the result of the $lookup is erroneous then we can investigate further.

Thanks,
Bruce

Generated at Thu Feb 08 04:31:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.