在MongoDB中,如何获取嵌入式文档的字段中的值,但如何基于不同的值进行查询 [英] In MongoDB, how does on get the value in a field for an embedded document, but query based on a different value
问题描述
我有这样的基本结构:
> db.users.findOne()
{
"_id" : ObjectId("4f384903cd087c6f720066d7"),
"current_sign_in_at" : ISODate("2012-02-12T23:19:31Z"),
"current_sign_in_ip" : "127.0.0.1",
"email" : "something@gmail.com",
"encrypted_password" : "$2a$10$fu9B3M/.Gmi8qe7pXtVCPu94mBVC.gn5DzmQXH.g5snHT4AJSZYCu",
"last_sign_in_at" : ISODate("2012-02-12T23:19:31Z"),
"last_sign_in_ip" : "127.0.0.1",
"name" : "Trip Jameson",
"sign_in_count" : 100,
"usertimes" : [
...thousands and thousands of records like this one....
{
"enddate" : 348268392.115282,
"idle" : 0,
"startdate" : 348268382.116728,
"title" : "My Awesome Title"
},
]
}
所以我只想查找标题为我的真棒标题"的单个用户的用户时间,然后我想查看该记录中"idle"的值是什么
So I want to find only usertimes for a single user where the title was "My Awesome Title", and then I want to see what the value for "idle" was in that record(s)
到目前为止,我能弄清楚的是,我可以通过以下搜索找到整个用户记录:
So far all I can figure out is that I can find the entire user record with a search like:
> db.users.find({'usertimes.title':"My Awesome Title"})
这只是返回整个用户记录,对我而言这是无用的.我误会了吗?
This just returns the entire User record though, which is useless for my purposes. Am I misunderstanding something?
推荐答案
MongoDB当前不支持仅返回部分嵌入式文档 匹配的用户记录将始终被返回(至少在当前的MongoDB版本中).
Return only partial embedded documents is currently not supported by MongoDB The matching User record will always be returned (at least with the current MongoDB version).
请参阅此问题以获取类似的参考
see this question for similar reference
这是MongoDB空间上的记者Jira
This is the correspondent Jira on MongoDB space
http://jira.mongodb.org/browse/SERVER-142
这篇关于在MongoDB中,如何获取嵌入式文档的字段中的值,但如何基于不同的值进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!