Here is the sample collections for the query, I want the result like given below. How can I show the details of device and user's details in issuedDevices
collection's document using mongo/nodejs query, please help:
1. collection user
/* 0 */
{
"_id" : 1,
"name" : "Pradeep",
"email" : "abc@gmail.com",
"createDate" : ISODate("2015-05-23T00:03:32.350-06:30")
}
/* 1 */
{
"_id" : 2,
"name" : "Steve",
"email" : "xyz@gmail.com",
"createDate" : ISODate("2015-05-23T00:04:02.362-06:30")
}
/* 2 */
{
"_id" : 3,
"name" : "Jonhy",
"email" : "xyz123@gmail.com",
"createDate" : ISODate("2015-05-23T00:04:30.834-06:30")
}
/* 3 */
{
"_id" : 4,
"name" : "Pinty",
"email" : "p123@gmail.com",
"createDate" : ISODate("2015-05-23T00:05:11.035-06:30")
}
2. collection Devices:
/* 0 */
{
"_id" : 1,
"name" : "iPad",
"owner" : "james"
}
/* 1 */
{
"_id" : 2,
"name" : "iPhone",
"owner" : "Micheal"
}
3. collection issuedDevices:
/* 0 */
{
"_id" : ObjectId("55602058a64447a5071a9a85"),
"userId" : 1,
"deviceId" : 1,
"isReturnd" : false,
"issuedDateTime" : ISODate("2015-05-23T00:08:16.354-06:30")
}
/* 1 */
{
"_id" : ObjectId("55602065a64447a5071a9a86"),
"userId" : 2,
"deviceId" : 1,
"isReturnd" : true,
"issuedDateTime" : ISODate("2015-05-23T00:08:29.355-06:30")
}
/* 2 */
{
"_id" : ObjectId("5560207da64447a5071a9a87"),
"userId" : 3,
"deviceId" : 1,
"isReturnd" : true,
"issuedDateTime" : ISODate("2015-05-23T00:08:53.615-06:30")
}
I want the result like given below, how can I show the details of device and user's details in issuedDevices
collection's document using mongo/nodejs query.
Expected Output
[
{
"_id" : ObjectId("5560207da64447a5071a9a87"),
"userId" : 3,
"deviceId" : 1,
"userDetails":{
"_id" : 3,
"name" : "Jonhy",
"email" : "xyz123@gmail.com",
"createDate" : ISODate("2015-05-23T00:04:30.834-06:30")
}
"deviceDetails":{
"_id" : 2,
"name" : "iPhone",
"owner" : "Micheal"
},
"isReturnd" : true,
"issuedDateTime" : ISODate("2015-05-23T00:08:53.615-06:30")
}
]