Comments (3)
Thanks for reporting, I opened up an issue in the mongoose repo so we can track this in mongoose's milestones.
from mongoose-autopopulate.
I can't repro this issue, the below code works correctly with mongoose 5.1.2 and mongoose-autopopulate 0.7.0. Can you modify the below script to reproduce your issue and clarify your versions of mongoose and mongoose-autopopulate?
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('debug', true);
const GITHUB_ISSUE = `gh6522`;
const connectionString = `mongodb://localhost:27017/${ GITHUB_ISSUE }`;
const { Schema } = mongoose;
run().then(() => console.log('done')).catch(error => console.error(error.stack));
async function run() {
await mongoose.connect(connectionString);
await mongoose.connection.dropDatabase();
const clientSchema = new mongoose.Schema({
service: {
net: {
radio: {
accessPointName: String
}
}
}
}, { toJSON: { virtuals: true }, toObject: { virtuals: true } });
clientSchema.virtual(`service.net.radio.accessPoint`, {
ref: `settings.accessPoint`,
localField: `service.net.radio.accessPointName`,
foreignField: `name`,
autopopulate: true
});
clientSchema.plugin(require(`mongoose-autopopulate`));
const Client = mongoose.model(`client`, clientSchema);
const accessPointSchema = new mongoose.Schema({
name: {
required: true,
type: String,
trim: true
}
}, { collection: `settings.accessPoints` });
const AccessPoint = mongoose.model(`settings.accessPoint`, accessPointSchema);
await AccessPoint.create({ name: 'test' });
await Client.create({ service: { net: { radio: { accessPointName: 'test' } } } });
const doc = await Client.findOne();
console.log(doc.toObject().service.net.radio.accessPoint);
}
Output:
$ node gh-6522.js
Mongoose: settings.accessPoints.insertOne({ _id: ObjectId("5b0981d32ef452707b660567"), name: 'test', __v: 0 })
Mongoose: clients.insertOne({ service: { net: { radio: { accessPointName: 'test' } } }, _id: ObjectId("5b0981d32ef452707b660568"), __v: 0 })
Mongoose: clients.findOne({}, { fields: {} })
Mongoose: settings.accessPoints.find({ name: { '$in': [ 'test' ] } }, { maxDepth: 10, _depth: 1, fields: {} })
[ { _id: 5b0981d32ef452707b660567, name: 'test', __v: 0 } ]
done
^C
$
from mongoose-autopopulate.
It turned out my find queries had .lean()
appended to them. I didn't expect that it might stop mongoose-autopopulate from triggering. Without lean() it works as expected. Sorry for that, the issue can be closed.
from mongoose-autopopulate.
Related Issues (20)
- How to disable auto populate when create. HOT 2
- can't use mongoose-autopopulate on recursively nested schema : Maximum call stack size exceeded HOT 2
- please use semantic versioning HOT 1
- How to hide the selected field which is necessary for the virtual field in the result data HOT 3
- Add support for nested autopopulated virtuals HOT 3
- Unable to initiate Autopopulate on Schema.plugin() HOT 2
- Issue with autopopulating a schema on itself HOT 1
- Autopopulate not working with findByIdAndDelete
- Virtuals populate match works with object but not with function HOT 1
- Missing `schemaStack` argument in `eachPathRecursive` method calling? HOT 2
- Missing types for plugin configuration HOT 1
- How to populate to virtuals HOT 1
- mongoose-autopopulate no longer works with mongoose 6.0 HOT 1
- Provide native Typescript types (instead of `@types/mongoose-autopopulate`) HOT 1
- autopopulate across databases HOT 3
- Tests failing with mongoose 6.2.4 HOT 2
- Doesn't autopopulate with refPath when documents are autopopulated from a virtual field HOT 4
- populate is not working! HOT 1
- It takes a lots of time
- Last defined discriminator of nested array discriminators is not populated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-autopopulate.