Intento buscar objetos con Mongoose (v4.6.2) usando populate. Aquí están mis modelos (en dos archivos diferentes):
const experienceSchema = new mongoose.Schema({ title: { type: String, maxlength: 50 }, creator: { type: Schema.ObjectId, ref: 'User' }, creatorName: String, city: { type: String, maxlength: 64 }, interests: [{ type: Schema.ObjectId, ref: 'Interest' }], }, { timestamps: true }); const interestSchema = new Schema({ Name: { type: String, default: '' }, illustration: { type: String, default: '' }, }, { timestamps: true });
Luego tengo una matriz: ["pizza", "GOT"]. Así que quiero encontrar todas las experiencias que tengan al menos un interés de la matriz. Así que hago esto:
experienceModel.find() .populate({ path: 'interests', match: { Name: { $in: array }} }) .exec(function(err, exps) {...}
Entonces, no sé por qué, el resultado contiene experiencias que no tienen ningún interés, especialmente las del array :(
¿Ves de dónde puede venir el problema?
Gracias que tengas un buen día :)