猫鼬在查找中使用当前文档的特定值

时间:2020-03-24 10:03:08

标签: mongodb mongoose

我在mongoDb和moongose中迈出了第一步。我想知道如何在查找查询中使用特定的文档值。 我的数据库中有这样的用户文档列表:

{
name:"test",
surname:"test",
restaurant:{
    location:{
        type: "Point",
                    coordinates: [30.000,l0.000]
    },
    state:"OPEN",
    selected:true,
    last_change:"2020-03-24 10:12:30"
    time:5
}}

这是我的查询

User.find({
                "restaurant.location":{
                    $nearSphere :{
                        $geometry: {
                            type: "Point",
                            coordinates: [latitude,longitude]
                        },
                        $maxDistance: distance
                    }
                },
                "restaurant.state":"OPEN",
                "restaurant.selected":true,
                "restaurant.last_change":{
                    $gte: moment(new Date()).subtract(20, "minutes").toDate(),
                    $lte: moment(new Date())
                }
            });

在这部分中,我将分钟数固定为20:

$gte: moment(new Date()).subtract(20, "minutes").toDate()

但是我想使用我餐厅的当前属性-> restauran.time并进行如下操作

$gte: moment(new Date()).subtract(restauran.time, "minutes").toDate(),

我不知道这是否正确,但是我的目标是让所有餐厅的last_change位于(当前时间)(当前时间-restaurant.time)之间

怎么办?

对不起,我的英语很高级

0 个答案:

没有答案