Tag: mongodb

The “__v” field in MongoDB

If you don’t need version_key, you can just:

var UserSchema = new mongoose.Schema({
    nickname: String,
    reg_time: {type: Date, default: Date.now}
}, {
    versionKey: false // You should be aware of the outcome after set to false
});

You can also call
resultFromMongo.toObject({ versionKey: false }),
to surppress the value.

In the example of  my lyric site, return the song by suppressing value. 🙂

  Model.findById(req.params.songId)
       .select({title:1,lines:1})
       .exec(function(err,song) {
         if(err)
            sendJsonResponse(res,400,err);
         else {
           song.lines
               .id(req.params.lineId)
               .translation
               .push(req.params.translation);
           song.save(function(error) {
             if(error)
                sendJsonResponse(res,400,error);
             else
               sendJsonResponse(res,200,song.toObject({ versionKey: false }));
           });

         }
       });