Mongo db returning empty results












0















My code:



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'123454'};
db.collection('userinfo').find(mquery,{'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}


am able to get the result from Robo3T mongo client but same is returning null through nodejs.



Robo3T:
db.getCollection('userinfo').find({_id:'66613'},{'_id':0,'subscriptions':1});









share|improve this question

























  • Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

    – Neil Lunn
    Nov 20 '18 at 4:44
















0















My code:



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'123454'};
db.collection('userinfo').find(mquery,{'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}


am able to get the result from Robo3T mongo client but same is returning null through nodejs.



Robo3T:
db.getCollection('userinfo').find({_id:'66613'},{'_id':0,'subscriptions':1});









share|improve this question

























  • Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

    – Neil Lunn
    Nov 20 '18 at 4:44














0












0








0








My code:



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'123454'};
db.collection('userinfo').find(mquery,{'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}


am able to get the result from Robo3T mongo client but same is returning null through nodejs.



Robo3T:
db.getCollection('userinfo').find({_id:'66613'},{'_id':0,'subscriptions':1});









share|improve this question
















My code:



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'123454'};
db.collection('userinfo').find(mquery,{'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}


am able to get the result from Robo3T mongo client but same is returning null through nodejs.



Robo3T:
db.getCollection('userinfo').find({_id:'66613'},{'_id':0,'subscriptions':1});






node.js mongodb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 6:58









Sangam Belose

1,85541724




1,85541724










asked Nov 20 '18 at 4:39









Cherry gCherry g

369




369













  • Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

    – Neil Lunn
    Nov 20 '18 at 4:44



















  • Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

    – Neil Lunn
    Nov 20 '18 at 4:44

















Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

– Neil Lunn
Nov 20 '18 at 4:44





Are you sure you are searching on the correct database and/or server? That's the only possible variance you are not showing here. The drivers work fine for the other couple of million people out there using it without problem, so the only cause here is you are actually pointing at different places. Or "wrong values" since you are in fact issuing a different query to what you are dating workds

– Neil Lunn
Nov 20 '18 at 4:44












1 Answer
1






active

oldest

votes


















1














You are searching a record by {_id:'66613'} in Robo3T but your sample is {_id:'123454'} in node.js. Also projection in node.js find is not in this way. Try below Snippet



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'66613'};
db.collection('userinfo').find(mquery).project({'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}





share|improve this answer
























  • Yes projection is wrong in my code. thanks for helping me in this.

    – Cherry g
    Nov 20 '18 at 6:42











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386345%2fmongo-db-returning-empty-results%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You are searching a record by {_id:'66613'} in Robo3T but your sample is {_id:'123454'} in node.js. Also projection in node.js find is not in this way. Try below Snippet



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'66613'};
db.collection('userinfo').find(mquery).project({'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}





share|improve this answer
























  • Yes projection is wrong in my code. thanks for helping me in this.

    – Cherry g
    Nov 20 '18 at 6:42
















1














You are searching a record by {_id:'66613'} in Robo3T but your sample is {_id:'123454'} in node.js. Also projection in node.js find is not in this way. Try below Snippet



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'66613'};
db.collection('userinfo').find(mquery).project({'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}





share|improve this answer
























  • Yes projection is wrong in my code. thanks for helping me in this.

    – Cherry g
    Nov 20 '18 at 6:42














1












1








1







You are searching a record by {_id:'66613'} in Robo3T but your sample is {_id:'123454'} in node.js. Also projection in node.js find is not in this way. Try below Snippet



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'66613'};
db.collection('userinfo').find(mquery).project({'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}





share|improve this answer













You are searching a record by {_id:'66613'} in Robo3T but your sample is {_id:'123454'} in node.js. Also projection in node.js find is not in this way. Try below Snippet



MongoClient.connect(gloabl_vars.db.mongo.url,function(err, db) {
if(err) { throw err; }
var dbo=db.db("profilemanager");
var mquery={_id:'66613'};
db.collection('userinfo').find(mquery).project({'_id':0,'subscriptions':1}).toArray(function(err,result){
if(err) throw err;
console.log(result);
});
});
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 6:09









Milad AghamohammadiMilad Aghamohammadi

841515




841515













  • Yes projection is wrong in my code. thanks for helping me in this.

    – Cherry g
    Nov 20 '18 at 6:42



















  • Yes projection is wrong in my code. thanks for helping me in this.

    – Cherry g
    Nov 20 '18 at 6:42

















Yes projection is wrong in my code. thanks for helping me in this.

– Cherry g
Nov 20 '18 at 6:42





Yes projection is wrong in my code. thanks for helping me in this.

– Cherry g
Nov 20 '18 at 6:42


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386345%2fmongo-db-returning-empty-results%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith