Skip to content

Mongoose plugin that replace document _id with id

Notifications You must be signed in to change notification settings

loulin/mongoose-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mongoose id Plugin

Simple plugin for Mongoose which replaces document attribute _id with id.

Installation

npm install mongoose-id

Usage

var mongoose = require('mongoose');
var idPlugin = require('mongoose-id');
var UserSchema = new mongoose.Schema({
    username: String
});
UserSchema.plugin(idPlugin);
mongoose.model('User', UserSchema);

By default, it will transform the document for both toJSON and toObject methods. You can disable any one by setting its option to false:

mongoose.plugin(idPlugin, {
  toJSON: false
});

Don't transform document for toJSON() of all schemas.

Setting options.remove to true will remove the id attribute:

UserSchema.plugin(idPlugin, {
  remove: true
});

License

The MIT License

About

Mongoose plugin that replace document _id with id

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published