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});
1
  • 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 Commented Nov 20, 2018 at 4:44

1 Answer 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); 
        });
    });
    }
Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.