title: MongoDB findOne() for retrieving from DB
body: <p>I am writing code in nodejs/MongoDB and am countering this particular issue which I was hoping to get help with:</p>
  
  <p>I have various schemas defined within my Models and I note that for each of these MongoDB automatically populates a unique id, which is represented by the <code>_id</code> field. </p>
  
  <p>However, I am interested in creating a customized ID, which is basically an integer that auto-increments. I have done so by utilizing the 'mongoose-auto-increment' npm package. For example, in my UserSchema:</p>
  
  <pre><code>UserSchema.plugin(passportLocalMongoose);
  
  module.exports = mongoose.model("User", UserSchema);
  autoIncrement.initialize(mongoose.connection);
  UserSchema.plugin(autoIncrement.plugin, {
    model: 'UserSchema',
    field: 'user_id',
    startAt: 1,
    incrementBy: 1
  });
  </code></pre>
  
  <p>To speed up my application, I have a seeds.js file which aims to load a bunch of data upon application initialization. However, to make this fully functional, I need a way to access my models and reference them over to other models (for cases when there is a one-to-one and one-to-many relationship). Since the mongoDB default <code>_id</code> is extremely long and there is no way to get the result unless I am actually on the html page and can use the <code>req.params.id</code> function, I have been trying to use mongoDB's <code>findOne</code> function to do this without success. </p>
  
  <p>For example:</p>
  
  <pre><code>var myDocument = User.findOne({user_id: {$type: 25}});
  if (myDocument) {
    var myName = myDocument.user_id;
    console.log(myName);
  }
  </code></pre>
  
  <p>However, the result is always 'undefined' even though I know there is a User model saved in my database with a user_id of 25. </p>
  
  <p>Any help would be much appreciated :)</p>