简体   繁体   English

猫鼬查询与$ near $或其他字段

[英]Mongoose query with $near $or other field

I'm attempting to return documents by doing a query $or on different fields including a $near query with problems. 我试图通过在不同的字段上执行查询$或包括有问题的$ near查询来返回文档。

Schema 架构

locationSchema{
    ...
    beacon: String,
    access_point: String,
    gps: [],
    ...
}

locationSchema.index({ gps: '2dsphere' });

Query 询问

locations.find({
    '$or': [
        {
            gps: {
                '$near': {
                    '$geometry': {
                        type: 'Point',
                        coordinates: [
                            13.1313131,
                            -4.444444
                        ]
                    },
                    '$maxDistance': 50,
                    distanceField: 'distance',
                    spherical: true
                }
            }
        },
        {
            access_point: '88:A6:BB:26:95:11'
        },
        {
            access_point: '88:A6:C6:26:CC:21'
        }
    ]
},
function(err,locations){
    //DosomethingwithfoundLocations
});

If I just do a query with only the $near input, there is one location returned as expected and if I do the query with just the list of access_point 's there is one location returned, but not when both queries are run at the same time. 如果仅使用$near输入执行查询,则将按预期返回一个位置;如果仅使用access_point的列表进行查询, access_point返回一个位置,但两个查询都在同一位置运行时,则不会返回时间。

I'm assuming this is a bug, but is there anyway I can get this type of query working? 我假设这是一个错误,但是无论如何,我可以使这种查询工作吗?

Thanks 谢谢

This is not supported according to the docs. 根据文档,这不受支持。 You can read more about it HERE : 您可以在此处了解更多信息:

$or supports geospatial clauses with the following exception for the near clause (near clause includes $nearSphere and $near). $ or支持地理空间子句,但Near子句具有以下例外(near子句包括$ nearSphere和$ near)。 $or cannot contain a near clause with any other clause. $ or不能与其他子句一起包含Near子句。

You can, however use geoWithin and pass in the center operator to achieve the same goal. 但是,您可以使用geoWithin并传入center运算符以实现相同的目标。 Keep in mind though that geoWithin does not sort the resulting array. 请记住,尽管geoWithin不会对结果数组进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM