Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose change _id to id

I would like to know how can i change the _id to id virtually or anyways so the direct json output from the database looks pretty. Additionally i see a __v generated in my documents and not sure how to hide those fields.

like image 652
Playdome.io Avatar asked May 10 '17 23:05

Playdome.io


1 Answers

if you want to hide __v in mongodb collection use versionKey: false in schema definition of collection.

example:

'use strict';

const mongoose = require('mongoose');

export class DeviceID extends mongoose.Schema {

    constructor() {
        super({
            device_id: String
        },
        {
            versionKey: false
        });
    }

}
like image 178
KARTHIKEYAN.A Avatar answered Nov 15 '22 20:11

KARTHIKEYAN.A