Skip to content

houstondapaz/mongoose-guid

Repository files navigation

mongoose-guid

GUID type for mongoose

bitHound Overall Score Coverage Status Build Status

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 GUID = require('mongoose-guid');
const mongoose = require('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 });