MongoDB:查询字段 [英] MongoDB: query for a field
本文介绍了MongoDB:查询字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在MongoDB集合中查询此文档的用户名"字段.集合名称称为上载.
I am trying to query the "Username" field of this document in a MongoDB collection. The collection name is called uploads.
这里是数据
{
"Timestamp": "2013-08-06T09:45:02.5677852-04:00",
"Operator": {
"Id": "94132d0b-f915-4205-a3b5-088dc017b9da",
"Username": "test",
"PasswordSha256": "590561e975aa1cbdaa6ff00da013dfb85656990eef11e504e9febe48a87d3642",
"FullName": "test",
"Enabled": "true",
"OperatorPrivilegeEnum": "Administrator",
"PasswordExpirationDate": "2013-11-04T09:40:51.7867096-05:00"
},
"AuditType": "GeneratedReport",
"Value": "Printed Setup Report on 6-Aug-2013 at 09:44:47"
}
我尝试使用
db.uploads.find({"Operator": {"Username": "test"}})
和
db.uploads.find({"Operator": {$elemMatch: {"Username": "test"}}})
我不确定文档的格式是否混乱.
I'm not sure if the formatting of the document is messed up or not.
我需要在Operator内找到部分应用程序的用户名.
I need to find the Username from within Operator for part of my application.
推荐答案
为此,您需要在查询对象键中使用点表示法:
You need to use dot notation in your query object key for that:
db.uploads.find({"Operator.Username": "test"})
这篇关于MongoDB:查询字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文