mongodb - 检索数组子集 [英] mongodb - retrieve array subset

查看:60
本文介绍了mongodb - 检索数组子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看似简单的任务,对我来说却是一个挑战.

what seemed a simple task, came to be a challenge for me.

我有以下 mongodb 结构:

I have the following mongodb structure:

{
(...)
"services": {
    "TCP80": {
      "data": [{
          "status": 1,
          "delay": 3.87,
          "ts": 1308056460
        },{
          "status": 1,
          "delay": 2.83,
          "ts": 1308058080
        },{
          "status": 1,
          "delay": 5.77,
          "ts": 1308060720
        }]
    }
}}

现在,以下查询返回整个文档:

Now, the following query returns whole document:

{ 'services.TCP80.data.ts':{$gt:1308067020} }

我想知道 - 我是否可以只接收那些符合 $gt 标准的数据"数组条目(缩小文档)?

我正在考虑使用 MapReduce,但找不到一个关于如何将外部参数(时间戳)传递给 Map() 函数的示例.(此功能在 1.1.4 https://jira.mongodb.org/browse/SERVER-401)

I was considering MapReduce, but could not locate even a single example on how to pass external arguments (timestamp) to Map() function. (This feature was added in 1.1.4 https://jira.mongodb.org/browse/SERVER-401)

另外,写storedJs函数总是有替代方法的,但是因为我们说的是大量的数据,所以这里不能容忍db-locks.

Also, there's always an alternative to write storedJs function, but since we speak of large quantities of data, db-locks can't be tolerated here.

很可能我必须将结构重新设计为 1 级深度,例如:

Most likely I'll have to redesign the structure to something 1-level deep, like:

{
   status:1,delay:3.87,ts:138056460,service:TCP80
},{
   status:1,delay:2.83,ts:1308058080,service:TCP80
},{
   status:1,delay:5.77,ts:1308060720,service:TCP80
}

但 DB 将急剧增长,因为服务"只是将附加每个文档的众多选项之一.

but DB will grow dramatically, since "service" is only one of many options which will append each document.

请多多指教!

提前致谢

推荐答案

目前不支持.默认情况下,除非您使用字段限制或 $slice 运算符,否则您将始终收到整个文档/数组.目前这些工具不允许根据搜索条件过滤数组元素.

This is not currently supported. By default you will always receive the whole document/array unless you use field restrictions or the $slice operator. Currently these tools do not allow filtering the array elements based on the search criteria.

您应该查看此请求以获取执行此操作的方法:https://jira.mongodb.org/browse/SERVER-828

You should watch this request for a way to do this: https://jira.mongodb.org/browse/SERVER-828

这篇关于mongodb - 检索数组子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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