问题描述
什么似乎一个简单的任务,前来对我来说是一个挑战。
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标准(一种收缩DOC)的作品
我正在考虑马preduce,但无法找到如何通过外部参数(时间戳)到map()函数甚至一个例子。 (此功能在1.1.4 )
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-锁在这里不能忍受的。
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.
请指教!
在此先感谢
推荐答案
这是目前不支持。默认情况下,除非你使用领域限制或$切片运营商,您将永远得到整个文档/阵列。目前这些工具不允许基于所述搜索标准过滤数组元素
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.
您应该看一个办法做到这一点这个请求:
You should watch this request for a way to do this: https://jira.mongodb.org/browse/SERVER-828
这篇关于MongoDB的 - 检索阵列集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!