[英]Mongoose Find Method not works correctly
我刚开始学习mongoose,我使用find方法从数据库中获取所有旅游数据,当我们没有在find方法中传递任何东西时,显示所有结果都是正确的,但是当我们尝试过滤所有文档并通过时错误的 object 进入 find 方法,该方法也显示所有游览,
我的TourSchema
const { Schema, model } = require("mongoose");
const tourSchema=new Schema({
name:{
type:String,
trim:true,
unique:true
},
price:{
type:Number,
require:[true,"A tour must have price"],
},
ratingsAverage:{
type:Number
},
ratingQuantity:{
type:Number,
},
duration:{
type:Number
},
ratingsAverage:{
type:Number,
default:4,
min:1,
max:5
},
difficulty:{
type:String,
enum:["easy","medium","difficult"]
},
maxGroupSize:{
type:Number,
require:[true,"A tour must have group size"],
},
description:{
type:String,
trim:true,
require:[true,'A tour must have description']
},
imageCover:{
type:String,
require:[true,'A tour must have imageCover']
},
images:[String],
startDates:{
type:[Date]
},
summary:{
type:String,
trim:true,
require:[true,"A tour must have summary"]
}
})
const Tour=new model('Tour',tourSchema);
module.exports=Tour;
findAllTour.js
exports.getAllTour =async(req, res) => {
try{
// console.log(req.query)
const tours=await Tour.find({"sjfa":5});
res.status(200).json({
status: "success",
results: tours.length,
data: {
tours
},
})
}
我在查找方法中传递了错误的字段,它的工作正常,意味着显示所有的游览
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.