I try to search objects with Mongoose (v4.6.2) using populate. Here are my models (in two different files) :
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 });
Then I have an array : ["pizza", "GOT"]. So I want to fin all experiences which have at least one interest of the array. So i do this :
experienceModel.find()
.populate({
path: 'interests',
match: { Name: { $in: array }}
})
.exec(function(err, exps) {...}
Then, I don't know why, the result contains experiences which have no interests, especially those of the array :(
Do you see where the problem could comes from ?
Thank you, have a nice day :)
via JulienBlc
No comments:
Post a Comment