die folgenden 3 Modelle Angenommen:Mongoose bevölkern verschachtelten Array
var CarSchema = new Schema({
name: {type: String},
partIds: [{type: Schema.Types.ObjectId, ref: 'Part'}],
});
var PartSchema = new Schema({
name: {type: String},
otherIds: [{type: Schema.Types.ObjectId, ref: 'Other'}],
});
var OtherSchema = new Schema({
name: {type: String}
});
Wenn ich für Autos abfragen kann ich die Teile füllen:
Car.find().populate('partIds').exec(function(err, cars) {
// list of cars with partIds populated
});
Gibt es eine Möglichkeit in Mungo die otherIds in dem aufzufüllen verschachtelte Teile Objekte für alle Autos.
Car.find().populate('partIds').exec(function(err, cars) {
// list of cars with partIds populated
// Try an populate nested
Part.populate(cars, {path: 'partIds.otherIds'}, function(err, cars) {
// This does not populate all the otherIds within each part for each car
});
});
ich wahrscheinlich über jedes Auto laufen kann und versuchen, bevölkern zu:
Car.find().populate('partIds').exec(function(err, cars) {
// list of cars with partIds populated
// Iterate all cars
cars.forEach(function(car) {
Part.populate(car, {path: 'partIds.otherIds'}, function(err, cars) {
// This does not populate all the otherIds within each part for each car
});
});
});
Problem ist, dass ich eine lib wie async zu verwenden haben die bevöl Aufruf für jeden zu machen und bis alle warten sind fertig und dann zurück.
Kann man ohne Schleife über alle Autos tun?
diese bevöl Methode findet in Ihrer get/post Route korrekt? – Winnemucca