-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Second level of populate doesn't work #5696
Comments
yeah, this is in the docs @stephanebressani, here's an example: const mongoose = require('mongoose');
const co = require('co');
mongoose.Promise = global.Promise;
const GITHUB_ISSUE = `gh-5696`;
exec()
.then(() => {
console.log('successfully ran program');
process.exit(0);
})
.catch(error => {
console.error(`Error: ${error}\n${error.stack}`);
});
function exec() {
return co(function* () {
yield mongoose.connect(`mongodb://localhost:27017/${GITHUB_ISSUE}`, { useMongoClient: true });
const deepNested = new mongoose.Schema({ name: String });
const DeepNested = mongoose.model('DeepNested', deepNested);
const nested = new mongoose.Schema({
deepNested: {
type: mongoose.Schema.Types.ObjectId,
ref: 'DeepNested'
}
});
const Nested = mongoose.model('Nested', nested);
const schema = new mongoose.Schema({
nested: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Nested'
}
});
const Model = mongoose.model('Model', schema);
const dn1 = yield DeepNested.create({ name: 'test' });
const n1 = yield Nested.create({ deepNested: dn1._id });
const m1 = yield Model.create({ nested: n1._id });
let doc = yield Model
.findById(m1._id)
.populate('nested'); // nested is populated
console.log('doc with nested populate', doc);
doc = yield Model
.findById(m1._id)
.populate('nested')
.populate('nested.deepNested');
console.log('doc with 2 populates', doc);
doc = yield Model
.findById(m1._id)
.populate({ path: 'nested', populate: { path: 'deepNested' }});
console.log('doc with correct populates', doc); // has deepNested populated
});
} |
Thank you ! it's works 👍
|
cool! |
Glad you found the issue 👍 @Spown thanks for your docs link but please be more respectful in the future 👍 🌴 |
submissionModel not working |
Hi, I am able to get the deepNested, but in my Database I am having a newDeepNested inside deepNested like
while using populate for nested how can I get the newDeepNest too. |
Do you want to request a feature or report a bug? (I don't know)
node version : 6.11.0
mongoose version : 4.11.13
mongodb : mLab
In Backend express.js:
populate "ingredients.DA01" doesn't work, populate "ingredients" (DA07RecIng) works, but the second level of populate (model "DA01Ingredient") in this exemple (picture above) doesn't work
Result in front-end:
Model from "DA02Recette" with a array "ingredients" to "DA07RecIng"
Model from "DA07RecIng"
Model from "DA01Ingredient"
Have you a trick to acomplish this ?
The text was updated successfully, but these errors were encountered: