0

我正在尝试在 MongoDB 集合中查询此文档的“用户名”字段。集合名称称为上传。

这是数据

{
"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"}}})

我不确定文档的格式是否混乱。

我需要从 Operator 中为我的应用程序的一部分找到用户名。

4

1 回答 1

2

You need to use dot notation in your query object key for that:

db.uploads.find({"Operator.Username": "test"})
于 2013-09-05T20:19:01.607 回答