2
IList<FilterDefinition<Family>> filters = new List<FilterDefinition<Family>>();
var filter = Builders<Family>
    .Filter.Eq(e=>e.id, "Andersen.1");
filters.Add(filter);

var filterPartiion = Builders<Family>
    .Filter.Eq(e => e.LastName, "Andersen");
filters.Add(filterPartiion);

var update = Builders<Family>.Update
    .Set<Boolean>(e=>e.IsRegistered, true);

var searchOn = Builders<Family>.Filter.And(filters);

collection.UpdateOne(searchOn, update);

在 Azure Cosmos DB 上使用 .net MongoDB.Driver,我想根据andIsRegistered的过滤器对文档元素进行更新,其中是分区键。我是 MongoDB 新手,我的代码是否正确?id="Andersen.1"LastName="Andersen"LastName

我收到一个错误:

“命令中的查询必须针对单个分片键”

[
  {
    "id": "Andersen.1",
    "LastName": "Andersen",
    "Parents": [
      {
        "FamilyName": null,
        "FirstName": "Thomas"
      },
      {
        "FamilyName": null,
        "FirstName": "Mary Kay"
      }
    ],
    "Children": [
      {
        "FamilyName": null,
        "FirstName": "Henriette Thaulow",
        "Gender": "female",
        "Grade": 6,
        "Pets": [
          {
            "GivenName": "Fluffy"
          }
        ]
      }
    ],
    "Address": {
      "State": "WA",
      "County": "King",
      "City": "Seattle"
    },
    "IsRegistered": false,
    "_rid": "S4UzAMRFRAABAAAAAAAAAA==",
    "_self": "dbs/S4UzAA==/colls/S4UzAMRFRAA=/docs/S4UzAMRFRAABAAAAAAAAAA==/",
    "_etag": "\"0100d5a1-0000-0000-0000-59b9d8cd0000\"",
    "_attachments": "attachments/",
    "_ts": 1505351885
  },
  ...
  ...
]
4

0 回答 0