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
[Question] Populate a Map #9359
Comments
Confirmed, here's the repro script: 'use strict';
const mongoose = require('mongoose');
const { Schema } = mongoose;
mongoose.set('debug', true);
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
await mongoose.connection.dropDatabase();
const parameter = Schema({
definition: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Definition',
},
value: {},
}, {_id: false});
const schema = Schema({
model: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Model'
},
name: String,
objectid: Number,
externalId: String,
properties: mongoose.Schema.Types.Mixed,
parameters: {
type: Map,
of: parameter
}
});
const Definition = mongoose.model('Definition', Schema({ text: String }));
const Element = mongoose.model('Element', schema);
const def = await Definition.create({ text: 'test' });
await Element.create({ parameters: { test: { definition: def } } });
const doc = await Element.findOne().populate('parameters.$*.definition');
console.log(doc.parameters);
} |
Thanks for reporting, fix will be in 5.10.3. You'll have to do |
I have schema type Map in my mongoose model. How to use refPath in Map?using "values.$*.refp" doesn't work. `const fieldValuesSchema = new Schema({ const rowSchema =new Schema ({ |
@ManimuthurajT where is |
Thanks for your response here is the definition of
|
@vkarpov15 repro script
|
@ManimuthurajT here's what you do what you're trying to do: const row = await Row.findOne().populate({
path: "values.$*.valueObject" // <-- no need for deep populate since `values` is already a property in row
}); There's a bug that prevents // row value schema
const rowValuesSchema = Schema({
valueObject: {
type: mongoose.Schema.Types.ObjectId,
ref: subdoc => subdoc.refp // <-- use `ref` function syntax rather than `refPath`
},
refp: {
type: mongoose.Schema.Types.String,
},
}); |
Question
I have schema type Map in my mongoose model. In this map, each element has reference to another model. I know that it's possible to populate attributes in array, but how about Map type? Be cause nesting like "map_type_attribute.some_attribute_to_populate" doesn't work. :)
This is my model:
This is how i'm trying to populate definition field:
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: v13.13.0
mongoose: 5.9.26
mongodb (docker): bitnami/mongodb:4.2.8-debian-10-r47
The text was updated successfully, but these errors were encountered: