I get the following error :
MongooseError: document must have an _id before saving
When I try to create an Object (Campagne) with uuid with my API using :
import uuidv4 from 'uuid/v4';
It works when I use :
const uuidv4 = require('uuid/v4');
My Campagne object is created correctly with its uuid.
Here is the full code of my object's Schema :
import * as mongoose from 'mongoose';
import uuidv4 from 'uuid/v4';
export const CampagneSchema = new mongoose.Schema({
_id: { type: String, default: uuidv4 },
dateDebut: Date,
dateFin: Date,
reduction: Number,
});
TSLint tell me to use import instead of require() and underline it as an error in my IDE but it's definitely not working as shown above.
Can someone explain me why is this happening please ?
For information, I use the NestJS node.js framework with Typescript.
To clarify :
I want to know why import is working for mongoose but not for uuid (require is working for uuid)