1***@qq.com
1***@qq.com
  • 发布:2025-06-05 16:34
  • 更新:2025-06-05 20:10
  • 阅读:43

【报Bug】查询·地理位置操作符 geoWithin 报错

分类:uniCloud

产品分类: uniCloud/支付宝小程序云

示例代码:
async queryRestaurentsByPolygon() {  
        try {  

            const area = new db.Geo.Polygon(  
                [  
                    new db.Geo.LineString([  
                        new db.Geo.Point(112.82216727560444, 28.134772708582847),  
                        new db.Geo.Point(113.00070445485858, 28.134772708582847),  
                        new db.Geo.Point(113.00070445485858, 28.46126612494616),  
                        new db.Geo.Point(112.82216727560444, 28.46126612494616),  
                        new db.Geo.Point(112.82216727560444, 28.134772708582847),  
                    ])  
                ]  
            )  
            console.log(JSON.stringify(area))  

            const res = await db.collection('restaurants_baseinfo').where({  
                location: db.command.geoWithin({  
                    geometry: area  
                })  
            }).get()  
            console.log(res)  
            return {  
                code: 0,  
                msg: '获取成功',  
                data: res.data,  
            }  
        } catch (error) {  
            //TODO handle the exception  
            console.log(error)  
            return {  
                errCode: 'DATABASE_ERROR',  
                errMsg: '数据库操作失败',  
            }  
        }  
    }

修改为

const area = new db.Geo.Polygon([  
                [  
                    new db.Geo.Point(112.82216727560444, 28.134772708582847),  
                    new db.Geo.Point(113.00070445485858, 28.134772708582847),  
                    new db.Geo.Point(113.00070445485858, 28.46126612494616),  
                    new db.Geo.Point(112.82216727560444, 28.46126612494616),  
                    new db.Geo.Point(112.82216727560444, 28.134772708582847),  
                ],  
            ])

后报错信息为Error: ==右侧值类型不正确

操作步骤:

在微信小程序中调用云对象中使用 geoWithin 操作符的方法时报错

预期结果:

能成功执行查询语句并返回数据

实际结果:

FaasError: invalid $geoWithin

bug描述:

在云对象中使用 db.command.geoWithin 方法 报错。
本地调试 和 云端调试 的日志输出报错信息均为:FaasError: invalid $geoWithin 。
前端调用平台: 微信小程序。
地理位置索引也配置了。
表字段,测试数据相关信息如图所示。

2025-06-05 16:34 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

再记录一下:
换成阿里云空间之后 查询语句可以正常运行了。
下图是jql测试运行结果。

要回复问题请先登录注册