【发布时间】:2022-01-16 06:52:11
【问题描述】:
"_id":{"$id":"61b5eb36029b48135465e766"},
"name":"push-ups","link":"https://google.com",
"image":"https://google.com",
"gender":["0","1","2"],
"goal":["lw","gw","sf"],
"age":60,
"excersietype":"chest",
"__v":0
这就是我的数据在数据库中的存储方式 我想根据3个条件获取数据
我从前面的性别目标和年龄得到 3 个查询,据此我必须检索数据
const gender = req.query.gender;
const age = req.query.age;
const goal = req.query.goal
const level = req.query.level
if (level==='fb'){
const getdata = new Forbeg.find({gender:{$in:gender}},{age:{$lte:age}},{goal:{$in:goal}});
console.log(getdata)
}
这是查找数据的好方法吗,因为我遇到了错误
UnhandledPromiseRejectionWarning: MongooseError: `Model.find()` cannot run without a model as `this`. Make sure you are not calling `new Model.find()`
我在获取时遇到错误
【问题讨论】:
-
我解决了我没有使用 await 的错误。但在此之后我仍然没有收到任何数据
标签: javascript node.js mongodb express mongoose