Reputation: 4517
My query is as shown below:
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);
});
});
};
Books.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);
Now,here my query gives me null result for console.log("book" +info)
even if the document is there inside the database, what is wrong with that query?
Upvotes: 0
Views: 133
Reputation: 15234
You are querying on incorrect field name
Books.findOne({ 'Book': book_name })
should be
Books.findOne({ Name: book_name })
Upvotes: 1