我有两个架构:
const BookSchema = new Schema({
name: { type: String, required: true },
author: [{ type: String }],
category: [{ type: String }],
store: { type:mongoose.Schema.Types.ObjectId, ref: 'Store'}
});
module.exports = mongoose.model('Book', BookSchema);
const storeSchema = new Schema({
name: { type: String, required: true },
slug: { type: String, index: true, required: true, unique: true}
});
module.exports = mongoose.model('Store', StoreSchema);
我试图从商店获取图书,描述如下:
exports.getBooksFromStore = async(idStore) => {
const data = await Book.find({store : idStore});
return data;
}
但是,以这种方式编写的find()并不起作用。
答案 0 :(得分:0)