mongoose-guid

2.0.1 • Public • Published

mongoose-guid

GUID type for mongoose

Mongoose GUID Data type

Why

In a .NET project? Yeah .NET GUID is a UUID V3 and node do not have support to this!

How to use

const mongoose = require('mongoose');
const GUID = require('mongoose-guid')(mongoose);
const Schema = mongoose.Schema;

const ProductSchema = Schema({
  _id: { type: GUID.type, default: GUID.value },
  name: String
}, { id: false });

ProductSchema.set('toObject', {getters: true});
ProductSchema.set('toJSON', {getters: true});

const Product = mongoose.model('Product', ProductSchema);

Arrays

To create arrays of GUIDs use the property Array

const ProductSchema = Schema(
  {
    _id: { type: GUID.type, default: GUID.value },
    ids: GUID.Array,
  },
  { id: false }
);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    175
    • latest
  • 0.0.2
    3
    • beta

Version History

Package Sidebar

Install

npm i mongoose-guid

Weekly Downloads

162

Version

2.0.1

License

MIT

Unpacked Size

13.1 kB

Total Files

10

Last publish

Collaborators

  • houstondapaz