猫鼬发现即使文件在那里也不会提供



我的查询如下所示:

const checkBook = (book_name) => {
console.log("book name " + book_name);
return new Promise((resolve, reject) => {
Books.findOne({ 'Book': book_name }).then((info) => {
if (!info) {
console.log("no book");
reject("there is no book");
}
console.log("book " + info);
resolve(info);
}).catch((err) => {
console.log("htytyyt" + err);
reject(err);
});
});
};

书籍.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Books = new Schema({
Name: {
type: String,
required: true
},
Author: {
type: String,
required: true
},
CurrentlyAvailableStatus: {
type: Boolean,
required: true,
default: true // true --> book available false --> book not available
}
}, {
versionKey: false
});

module.exports = mongoose.model('books', Books);

现在,我的查询给了我 null 结果console.log("book" +info)即使文档在数据库中,该查询有什么问题?

您正在查询不正确的字段名称

Books.findOne({ 'Book': book_name })

应该是

Books.findOne({ Name: book_name })

相关内容

最新更新