hei im try to get data with range between field_1 and field_2 but it always return null
here my code
let limit = 10;
let skip = 0;
let conditions = {
depth_1 : {"$gte" :parseInt(req.body.depth_1)},
depth_2 : {"$lte" :parseInt(req.body.depth_2)}
}
let showImage = await Image.find(conditions).limit(limit).skip(skip).exec(function(err, docs){
res.send(docs)
these code always returning null even i have that data in my db
my json data:
[
{
"mode": "W",
"_id": "5bd3e4890ec2f91a7d9309e9",
"filename": "VH009_15.95-20.95_W.png.png",
"path": "/home/harisman/dugong/H/bismillah/public/images/VH009_15.95-20.95_W.png.png",
"hold_id": "VH009",
"depth_1": 1595,
"depth_2": 2095,
"__v": 0,
"createdAt": "2018-10-27T04:07:37.785Z",
"updatedAt": "2018-10-27T04:07:37.785Z"
}
]
my req.body :
{
"depth_1" : 1595,
"depth_2" : 2095
}
答案 0 :(得分:1)
此行:
let showImage = await Image.find(conditions).limit(limit)
.skip(skip).exec(function(err, docs) {})
您正在使用await和callback ...试试这个:
let showImage = await Image.find(conditions).limit(limit)
.skip(skip).exec()
或者这也应该工作:
let showImage = Image.find(conditions).limit(limit)
.skip(skip).exec().then(docs => console.log(docs))
两者都取决于exec
实际上提供了完整的承诺