MST

星途 面试题库

面试题:MongoDB地理空间索引之中等难度位置查询题

假设有一个存储店铺位置信息的MongoDB集合,文档结构包含店铺名称(name)和地理位置(location,使用GeoJSON格式)。现在要求查询距离坐标点[116.4074, 39.9042] 5公里范围内的所有店铺,写出对应的MongoDB查询语句。
29.5万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试
db.collection.find({
    location: {
        $near: {
            $geometry: {
                type: "Point",
                coordinates: [116.4074, 39.9042]
            },
            $maxDistance: 5000
        }
    }
});