-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.lean does not work with mongoose 5.0.0 #6
Comments
Thanks for reporting, opened an issue in the mongoose repo to track |
I can't reproduce this issue, the following script works fine. Can you modify it to reproduce your issue? const mongoose = require('mongoose');
const mongooseLeanVirtuals = require('./');
const schema = new mongoose.Schema({
name: String
});
schema.virtual('lowercaseName').get(function() {
return this.name.toLowerCase();
});
schema.plugin(mongooseLeanVirtuals);
const Model = mongoose.model('t1', schema);
run().catch(error => console.error(error.stack));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test');
await Model.deleteMany({});
const doc = await Model.create({ name: 'Val' });
console.log(await Model.findById(doc._id).lean({ virtuals: true }));
console.log('done');
} |
Hi, Issue occured if we used alias in schema. you can reproduce error with this change. const mongoose = require('mongoose');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
const schema = new mongoose.Schema({
name: {
type: String,
alias: 'Member Name'
},
});
schema.virtual('lowercaseName').get(function() {
return this.name.toLowerCase();
});
schema.plugin(mongooseLeanVirtuals);
const Model = mongoose.model('t1', schema);
run().catch(error => console.error(error.stack));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test');
await Model.deleteMany({});
const doc = await Model.create({ name: 'Val' });
console.log(await Model.findById(doc._id).lean({ virtuals: true }));
console.log('done');
} |
Thanks for helping repro. Fix will be in mongoose 5.0.4. |
Would it be possible to inject this fix also to work in mongoose 4.* branch? |
@vmattila what is preventing you from upgrading to Mongoose 5.x? |
@vkarpov15 unfortunately the database environment is still on MongoDB 2.6, and it requires 4.x version (https://mongoosejs.com/docs/compatibility.html). That saying, 2.6 is already EOL, so I understand if fixing 4.* is not feasible. |
@vmattila we just shipped 4.13.20 with the fix 👍 Normally we don't backport fixes to 4.x though, so I would strongly recommend upgrading your MongoDB server. |
Hi,
.lean with virtual was working fine when using mongoose 4.0. After updating it to mongoose 5.0.0, we get this error while using .lean with virtuals.
"Error: this.get is not a function",
The text was updated successfully, but these errors were encountered: