У меня проблема с заполнением моей OfferSchema.
Когда я пытаюсь получить забронированные предложения от текущего пользователя, я получаю сообщение об ошибке MissingSchemaError: Schema hasn't been registered for model "offer"
от mongoose.
Поле арендатора заполнено правильно.
Я пробовал много способов решить эту проблему, даже из официальных документов, но никто не проходил мимо меня.
Буду признателен за любую помощь, спасибо.
Схема моей книги
const BookSchema = new Schema({
tenant: {
type: Schema.Types.ObjectId,
ref: 'user'
},
...
offer: {
type: Schema.Types.ObjectId,
ref: 'offer'
}
});
const BookModel = mongoose.model('books', BookSchema);
module.exports = BookModel;
Схема моего предложения
const OfferSchema = new Schema({
...
author: {
type: Schema.Types.ObjectId,
required: true,
ref: 'user'
}
});
const OfferModel = mongoose.model('offers', OfferSchema);
module.exports = OfferModel;
Как я пытаюсь получить результат
const landlord = req.userData.userId;
Book.find().populate('tenant', 'email').populate({
path: 'offer',
match: {
'author': {
$eq: landlord
}
}
}).then(books => {
res.status(200).json({books: books})
}).catch(err => {
console.log(err);
res.status(500).json({error: err.message})
});