I have read some solutions regarding this in stack overflow, but none suits my situation.
My mongo db collection _id is a composite key as shown below,
Mongo db Application Collection
{
"_id" : {
"appId" : 1,
"name" : "my app"
},
"dataLoaded" : true,
"__v" : 0
}
my code (gives empty result)
app.get('/api/application',function(req,res){
Application.findOne({"_id" : req.query._id},function(err,application){
if(err){
res.status(500).send(err);
}else{
if(application){
console.log("entered")
res.status(200).send(application);
}else{
res.status(404).send(err);
}
}
})
});
my code (gives a document as result)
app.get('/api/application',function(req,res){
Application.findOne({"_id" : {"appId" : 1,"name" : "my app"}},function(err,application){
if(err){
res.status(500).send(err);
}else{
if(application){
console.log("entered")
res.status(200).send(application);
}else{
res.status(404).send(err);
}
}
})
});
where as when my console.log(req.query._id)
results {"appId" : 1,"name" : "my app"}
I can't understand what mistake I made. When _id is not a composite key then everything works fine.
Thanks in advance !!