title: Mongoose does not return _id in findOne
body: <p>To get better storage and to use UUID's as the primary key, I customize the default functionality for _id to store as a UUID as a binary bson type 4. I then setup a virtual for id to return the value of _id.</p>
  
  <p>Here is an example schema using ES6 as described:</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  require('mongoose-uuid2')(mongoose);
  const UUID = mongoose.Types.UUID;
  const uuid = require('node-uuid');
  const bson = require('bson');
  
  const schema_options = { 
      id: false,
      getters: true,
      virtuals: true,
      toObject: {
          versionKey: false,
          transform: function (doc, ret) {
              delete ret.__v;
              //delete ret._id;
          }
  },
      toJSON: {
          versionKey: false,
          transform: function (doc, ret) {
            //delete ret._id;
            delete ret.__v
          }
        }  
  };
  
  const BaseSchema = new Schema (
      {
          _id: { type: UUID, default: uuid.v4, required: true },
          code: { type: String },
          name: { type: String },
          timestamps: { 
              created: {type: Date, required: true},
              updated: {type: Date, required: true}
          },
          __v: { type: Number, select: false}
      }, schema_options
  );
  
  class BaseSchemaClass {
  
      //virtuals
      get id() {
          return this._id;
      }
  
      set id(uuid_string){
  
          console.log(uuid_string);
          let uuid_parse = uuid.parse(uuid_string);
          console.log(uuid_parse);
          let id_buffer = new mongoose.Types.Buffer(uuid_parse);
          id_buffer.subtype(bson.Binary.SUBTYPE_UUID);
          console.log(id_buffer);
          this._id = id_buffer.toObject();
      }
  
      //private
      static convert_uuid_string_to_buffer (uuid_string) {
  
          var uuid_parse = uuid.parse(uuid_string);
          var id = new db.Types.Buffer(uuid_parse);
          id.subtype(bson.Binary.SUBTYPE_UUID);
          return id.toObject();
      }
  }
  
  BaseSchema.loadClass(BaseSchemaClass);
  module.exports = BaseSchema;
  </code></pre>
  
  <p>The schema data appears to update and you can read the data as expected. In addition, it appears that saves to the database occur as expected as well. </p>
  
  <p>Here is an example record:</p>
  
  <pre><code>{ "_id" : BinData(4,"yyfw80jURj+35wguKCKJRg=="), "timestamps" : { "updated" : ISODate("2018-01-28T19:47:05.825Z"), "created" : ISODate("2018-01-28T19:47:05.825Z") }, "code" : "MAR", "name" : "Michael", "__v" : 0 }
  </code></pre>
  
  <p>However, when using mongoose to find a record, using a non "_id" field, the "_id" field does not return. The virtual retreives the _id and it is undefined. </p>
  
  <p>Here is an example in using the schema.</p>
  
  <pre><code>const BaseSchema = require('./schemas/base');
  const mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/test');
  mongoose.set('debug', true);
  mongoose.Promise = require("bluebird");
  
  let db = mongoose.connection;
  db.on('error', console.error.bind(console, 'connection error:'));
  db.once('open', function() {
  
      const BaseModel = mongoose.model('Base', BaseSchema);
  
      let base_document = new BaseModel({code: "MAR", name: "Michael", timestamps :{updated: new Date(), created: new Date() }});
      console.log(base_document.id)
      console.log(base_document.code)
      base_document.save()
      .then(() =&gt; {
        return Promise.resolve();  
      })
      .then(() =&gt; {
  
          return BaseModel.findOne({code: "MAR"}).exec();
      })
      .then((record) =&gt; {
          //fails
          console.log(record.id)
          console.log(record.code)
          console.log(record);
          return BaseModel.findByIdAndUpdate(record.id, { $set: { name: 'Steve', code: "STV" }});
      })
      .then(() =&gt; {
  
          return BaseModel.findOne({name: "Steve"}).exec();
      })
      .then((record) =&gt; {
          //fails
          console.log(record.id);
          console.log(record.code);
          console.log(record);
          db.close();
      })
      .catch((err) =&gt; {
          console.log(err);
          db.close();
      });
  });
  </code></pre>
  
  <p>I am at a loss on why the _id is not returning in the schema, I have tried variations of find and find an update of the above but it still does not return the _id. I need some assistance in determining the problem.</p>
  
  <p>Here is the versions of npm packages I am using</p>
  
  <pre><code>"bluebird": "^3.5.1",
  "bson": "^1.0.4",
  "mongoose": "^5.0.1",
  "mongoose-uuid2": "^2.0.2",
  "node-uuid": "^1.4.8"
  </code></pre>
  
  <p>I have tried using node 9.2.0 and 8.9.4 with the same result.</p>
  
  <p>I am also using mongo 3.2</p>