我的查询如下所示:
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);
Books.js
console.log("book" +info)
现在,我的查询为{{1}}提供了空结果,即使文档在数据库中,该查询有什么问题?
答案 0 :(得分:1)
您正在查询错误的字段名称
Books.findOne({ 'Book': book_name })
应该是
Books.findOne({ Name: book_name })