ReNiSh AR
ReNiSh AR

Reputation: 2852

Mongo Model.find with condition not working

MongoDb: The condition in find method not working, fetching no records

I'm using mongoose in my application,

AppUser.find({'applicationId' : '58abf9bdc3aa0f1b0b2e3c85'}, function (err, obj) {
   if(err) {
      console.log(err);
   } else {
     console.log(obj);
   }
});

But using without condition in find, working fine: AppUser.find({}, function (err, obj)...

Below is my schema sample:

enter image description here

has also set a reference in applicationId field

Upvotes: 0

Views: 690

Answers (2)

dan
dan

Reputation: 1984

You need to call toArray on it:

AppUser.find({'applicationId' : '58abf9bdc3aa0f1b0b2e3c85'}).toArray(function(err, docs) {
     if(err) {
           console.log(err);
     }
     else {
           console.log(docs)
     }
})

Upvotes: 1

Ahmed farag mostafa
Ahmed farag mostafa

Reputation: 2964

use where

AppUser.find().where({applicationId:'58abf9bdc3aa0f1b0b2e3c85'}).exec(function(err, obj){
    if(err) {
      console.log(err);
   } else {
     console.log(obj);
   } 
});

Upvotes: 0

Related Questions