0

I have a user collection which has 1000 documents,when i call find() function using mongoose in node.js,it does not return any result or throw any error. But when i query through mongo shell it returns all results. Neither the docs nor the err is getting consoled,it just hangs.The same query is working when queried for less no. of documents.

var userschema = require('./models/profile.js');

userschema.find({ 'dept_id': data }, function(err, docs) {
    if (err)
        console.log(err);
    console.log(docs);
});

profile.js

var mongoose = require('mongoose');

var profileSchema = new mongoose.Schema({
   dept_id:{
    type:String,
    default:''
   },
   email:{
    type:String,
    default:''
   },
   loggedin_time:{
    type:Number,
    default:0
   },
   phone_number:{
    type:String,
    default:''
   },
   password:{
    type:String,
    default:''
   },
   gender:{
    type:String,
    default:''
   },
   dob:{
    type:String,
    default:''
   },
   profile_pic:{
    type:String,
    default:''
   },
   city:{
    type:String,
    default:''
   },
   state:{
    type:String,
    default:''
   },
   country:{
    type:String,
    default:''
   },
   last_seen:{
    type:String,
    default:''
   }
});
module.exports = mongoose.model('profiles',profileSchema);

Thank you.

Alex
  • 37,502
  • 51
  • 204
  • 332
scionoftech
  • 608
  • 2
  • 9
  • 24
  • 2
    Can you use the [edit] link to include the `userschema` definition? I strongly suspect you haven't defined the `User` model from the mongoose instance with the above schema, like e.g. `var User = mongoose.model('User', userschema);` and you are querying with the `userschema` instead of the mongoose model. – chridam May 31 '16 at 08:04
  • hi,thanks for reply i have already defined usershema. – scionoftech May 31 '16 at 08:35
  • Where have you defined it? – chridam May 31 '16 at 08:36
  • var userschema = require('./models/profile.js');userschema.find({'dept_id':data.id},function(err,docs){ if(err)console.log(err); console.log(docs); }); – scionoftech May 31 '16 at 08:38
  • 2
    @sky add your schema _and_ your model declaration to your question, please. – robertklep May 31 '16 at 08:41
  • 1
    EDIT your question and post the code for **models/profile.js** – Alex May 31 '16 at 08:42
  • i have updated my question, neither the docs nor the err is getting consoled,it just hangs.The same query is working when queried for less no. of documents. – scionoftech May 31 '16 at 08:53

0 Answers0