0

我用了find还可以:</p>

{
    $and:[
        {"online":1},
        {"uptime":{$gte: new Date(2012,8,16,2,51)}}
    ]
}

以下命令也可以:

{
    geoNear : "Driver", 
    near : [120.105148,30.447977 ],
    num : 100,
    spherical : true,
    maxDistance :500/6378,
    query:{"online":1}
}

但我将 geoNear 命令与地理空间索引一起使用,我什么也得不到:

{
    geoNear : "Driver", 
    near : [120.105148,30.447977 ],
    num : 100,
    spherical : true,
    maxDistance :500/6378 ,
    query:{
        $and:[
            {"online":1},
            {"uptime":{$gte: new Date(2012,8,16,2,51)}}
        ]
    }
}

要求是:我想在10分钟内让他们更新位置的在线客户,怎么做?我创建了名为“pos”的地理空间索引,包括列:正常运行时间和在线

谢谢。

4

2 回答 2

0

您不需要 $and 在查询中。如果添加两个字段,则只返回同时满足这两个条件的文档。

试试这个:

db.runCommand(
    {
        geoNear : "Driver", 
        near : [120.105148,30.447977 ],
        num : 100,
        spherical : true,
        maxDistance :500/6378 ,
        query: { "online": 1,
                 "uptime": {$gte: new Date(2012,8,16,2,51)}

        }
    }
)

仅当您想在同一字段上有两个条件,或者如果您想制定涉及 $and 和 $or 的更复杂的逻辑查询时,才需要 $and。有关更多信息,请参阅$and 文档

于 2012-09-17T07:29:10.877 回答
0

thks at first; I used the $or instead of the $and, it also could not work, I need use the $or; now, I add a Millisecond(long type) column that it convert from the Date column , and I changed the Date column as the following, It worked:

{
geoNear : "Driver", 
near : [120.105148,30.447977 ],
num : 100,
spherical : true,
maxDistance :500/6378 ,
query:{
    $or:[
        {"online":2},
        {"online":1,"uptimestap":{$gte: 1348156800000}}
    ]
}
}
于 2012-09-24T02:12:27.383 回答