基于数组中特定位置的项目的Mongodb查询 [英] Mongodb query based on item at specific position in array

查看:24
本文介绍了基于数组中特定位置的项目的Mongodb查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个查询,其中需要比较数组中特定位置的项目.

I want to run a query where an item at a specific position in an array needs to be compared.

例如,考虑用于存储位置数据的 GeoJSON 格式.

For example, consider the GeoJSON format for storing location data.

//sample document from collection user
{
    name: "Some name",
    location : {
        type: "Point",
        coordinates : [<Longitude>, <Latitude>]
    }
}

如何查询位于特定经度的用户?

How would I query users located at a specific longitude?

我似乎在文档中找不到任何可以帮助我做同样的事情.

I cant seem to find anything in the documentation which can help me do the same.

我尝试过的查询:

db.users.find({"location.coordinates[0]" : -73.04303})

推荐答案

将您的查询更改为以下内容

Change your query to the following

   db.users.find({"location.coordinates.0" : -73.04303})

这篇关于基于数组中特定位置的项目的Mongodb查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆