mongoose-lean-defaults
Attach defaults to the results of mongoose queries when using .lean()
.
Highly inspired by mongoose-lean-virtuals.
Install
npm install --save mongoose-lean-defaults
or
yarn add mongoose-lean-defaults
Usage
import mongooseLeanDefaults from 'mongoose-lean-defaults';
const userSchema = new mongoose.Schema({
name: {
type: String,
default: 'Bob',
},
});
const updatedUserSchema = new mongoose.Schema({
name: {
type: String,
default: 'Bob',
},
country: {
type: String,
default: 'USA',
},
});
updatedUserSchema.plugin(mongooseLeanDefaults);
const bob = await UserModel.findOne().lean({ defaults: true });