Tuesday, 5 January 2021

($toObjectId) stiing convert to ObjectId in MongoDb/Mongoose

Signal // .find({ subscriberId: req.query.subscriberId }) .aggregate([ { "$addFields": { "mentorId0": { "$toString": "$mentorId" } } }, { "$addFields": { "mentorIdObj": { "$toObjectId": "$mentorId" } } }, // { "$match": {"subscriberId": subscriberId } }, { "$lookup": { "from": "subscribementors", "localField": "mentorId0", "foreignField": "mentorId", "as": "mentor" }, }, { $match: { // "mentorId": "5fdb1f7b807d6916186428bf", "mentor.subscriberId": subscriberId // "mentor.mentorId": "5fdb1f7b807d6916186428bf" // } // "subscriberId": "5fdb1b4890d271394844e20a" // "mentor":[{"subscriberId":subscriberId}] } }, { "$lookup": { "from": "mentors", "foreignField": "_id", "localField": "mentorIdObj", "as": "mentorDetail" } }, // { "$project":{$cond:{"mentor":{"subscriberId":subscriberId}}} } // {"$project":{"subscriberId":1,"mentorId":1,"mentor":{name:1,email:1,status:1}}} ]) .then(mySignal => { res.send({ mySignal: mySignal }); }).catch(err => { res.status(500).send({ Message: err.message, Result: false, data: err }); })

No comments:

Post a Comment

IIS deployment support details

  Node JS - IIS deployment support details node: http://go.microsoft.com/?linkid=9784334 IISNode: https://github.com/azure/iisnode/releases/...