Database

db={users:[{_id:ObjectId("5a934e000102030405000001"),name:"mittul",email:"mittul@gmail.com",password:"xyz"},{_id:ObjectId("5a934e000102030405000002"),name:"rahul",email:"rahul@gmail.com",password:"abc"}],categories:[{title:"third cake",userid:ObjectId("5a934e000102030405000001")},{title:"forth cake",userid:ObjectId("5a934e000102030405000001")}]}

Query

db.users.aggregate([{$match:{_id:ObjectId("5a934e000102030405000001"),name:"mittul"}},{$lookup:{from:"categories",localField:"_id",foreignField:"userid",as:"categories"}},{$set:{"categories":{$cond:{if:{$eq:["$categories",[]]},then:"$$REMOVE",else:"$categories"}}}}])

Result