Monday 8 May 2017

Is it possible to add fields not described in Mongoose model?

For example I have schema like this:

let mongoose = require('mongoose');

let carSchema = new mongoose.Schema({
    url:  String,
    unique: {type: String, index: { unique: true }},
    number: String,
    title: String,
    price: String,
});

module.exports = mongoose.model('Car', carSchema);

When I'm creating new instance is it possible to add extra fields without describing them in the model? For example:

data.bpm = {foo: 'bar'}

new CarModel(data).save(function (err) {
    if (err) {
        dd(err)
    }
})



via user1692333

No comments:

Post a Comment