简体   繁体   中英

DocumentDB Document Id

I'm using DocumentDB on azure and I don't want the auto-generated GUID that it gives me for an id on the top layer...example:

{ "data": { "Name": "Brian", "Last": "Coolest", "gender": "m" }, "id": "7c572c3f-2ee1-43c9-bfb9-63b67542658d" }

how do i turn that id into:

 {
  "data": {
    "Name": "Brian",
    "Last": "Coolest",
    "gender": "m"
  },
  "id": "Brian"
}

on the creation of the document, is this possible? Thanks!

here is the method:

client.CreateDocumentAsync(
                    UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), JsonSerializedDocument);

example of json structure:

{
  "data": {
    "id": "113118",
    "url": "/v1/rentalUnits/202020202",

Yes, if you add your own field named "id" populate the field before you save the document, then DocDb will use the id you specified. But, that means you have to control the uniqueness of the primary keys otherwise the next document that you save with "id":"Brian" will obviously overwrite the previous document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM