9

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.

Playdome.io
  • 3,137
  • 2
  • 17
  • 34
  • Does this answer your question? [MongoDB: output 'id' instead of '\_id'](https://stackoverflow.com/questions/7034848/mongodb-output-id-instead-of-id) – Peter Sobhi Nov 04 '19 at 15:26

1 Answers1

2

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
        });
    }

}
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133