ReplaceDocumentAsync without Document is that possible?

Thomas Segato

I query a document and send it to my Angular application. Then I edit the model and send it back. My question is can you update a document from the model only? Document does not have any constructors, and ReplaceDocumentAsync requires Document? Or do I have to query the document first just to get same object i then I have to edit?

public void Put([FromBody] VesselView vessel)
{
   var collectionLink = UriFactory.CreateDocumentCollectionUri("AssetControl", "Vessels");
  _cosmosDocClient.ReplaceDocumentAsync(vessel);

}
Imre Pühvel

Yes, you can. You only have to know the id of document you want to replace. Tested with .Net client Microsoft.Azure.DocumentDB v2.2.1.

This can be achieved when passing the intended new document as JObject. You can use any Json serializer for this. Also, note that your model does not have to contain the internal document fields like _rid, _ts, etc

Example code:

var client = new DocumentClient(url, key, policy);
var documentUri = UriFactory.CreateDocumentUri("myDB", "myCollection", "_replaceTest");

var newModel = JObject.Parse(@"{""id"": ""_replaceTest"",   ""myData"": ""replaced!""}");
var response = await client.ReplaceDocumentAsync(documentUri, newModel);
var fromStorage = response.Resource;

Returned model is the full model containing the extra model fields:

{
  "id": "_replaceTest",
  "_rid": "FOOBAR==",
  "_self": "dbs/FOO==/colls/BAR=/docs/FOOBAR==/",
  "_ts": 1550491238,
  "_etag": "\"0000e379-0000-0000-0000-5c6a9e660000\"",
  "myData": "replaced!"
}

Obviously, as David Makogon hinted, you cannot rely on _etag check this way, unless you include this property in the model you send to DocumentDB.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Is encapsulation possible without OOP?

分類Dev

It is possible to code `if(($(document).onmouseup) && (value_ == 1))`?

分類Dev

Possible to dispatch an action without connect?

分類Dev

how to update a document without overwriting the existing one?

分類Dev

Jquery document.ready not triggered without alert

分類Dev

output translations without document.write

分類Dev

Is it possible to restart the unity panel without restarting compiz?

分類Dev

Is it possible to change ownership of a file without root access?

分類Dev

Is it possible to work without tmux on current Debian?

分類Dev

Is it possible to use ActiveStorage without a file input?

分類Dev

Is it possible to read a file without loading it into memory?

分類Dev

Bottle - Is it possible to retrieve URL without parameters?

分類Dev

Is it possible to define the height of a row in a UITableView without an UITableViewController?

分類Dev

Is it possible to put root in LVM without using initrd?

分類Dev

Is it possible to enable NTFS compression without formatting?

分類Dev

All possible N choose K WITHOUT recusion

分類Dev

Possible to save OpenXML Spreadsheet without calling Close()?

分類Dev

Is it possible to show/hide an element in a parent without rerendering?

分類Dev

Is it possible to display an .html document , or .html fragment at CSS content?

分類Dev

With firestore, is it possible to configure offline persistence to set 'off' in a specific document?

分類Dev

Is it possible to read a document in Firestore and then lock it, so nobody else can read it?

分類Dev

Is it possible to move to the end of document with some hot-key?

分類Dev

Is it possible to have a website, like a text-based document?

分類Dev

Is it possible to capture the user name or ID of the person uploading an Oracle WebADI document?

分類Dev

How to make part of rmarkdown document without section numbering?

分類Dev

Access to a webpage's frame document without navigating to this webpage

分類Dev

How to get UID from an Angular fire store Document without snapshot

分類Dev

How to remove a specific part of a text document without using range() python

分類Dev

how to change document scroll speed in react without jquery

Related 関連記事

  1. 1

    Is encapsulation possible without OOP?

  2. 2

    It is possible to code `if(($(document).onmouseup) && (value_ == 1))`?

  3. 3

    Possible to dispatch an action without connect?

  4. 4

    how to update a document without overwriting the existing one?

  5. 5

    Jquery document.ready not triggered without alert

  6. 6

    output translations without document.write

  7. 7

    Is it possible to restart the unity panel without restarting compiz?

  8. 8

    Is it possible to change ownership of a file without root access?

  9. 9

    Is it possible to work without tmux on current Debian?

  10. 10

    Is it possible to use ActiveStorage without a file input?

  11. 11

    Is it possible to read a file without loading it into memory?

  12. 12

    Bottle - Is it possible to retrieve URL without parameters?

  13. 13

    Is it possible to define the height of a row in a UITableView without an UITableViewController?

  14. 14

    Is it possible to put root in LVM without using initrd?

  15. 15

    Is it possible to enable NTFS compression without formatting?

  16. 16

    All possible N choose K WITHOUT recusion

  17. 17

    Possible to save OpenXML Spreadsheet without calling Close()?

  18. 18

    Is it possible to show/hide an element in a parent without rerendering?

  19. 19

    Is it possible to display an .html document , or .html fragment at CSS content?

  20. 20

    With firestore, is it possible to configure offline persistence to set 'off' in a specific document?

  21. 21

    Is it possible to read a document in Firestore and then lock it, so nobody else can read it?

  22. 22

    Is it possible to move to the end of document with some hot-key?

  23. 23

    Is it possible to have a website, like a text-based document?

  24. 24

    Is it possible to capture the user name or ID of the person uploading an Oracle WebADI document?

  25. 25

    How to make part of rmarkdown document without section numbering?

  26. 26

    Access to a webpage's frame document without navigating to this webpage

  27. 27

    How to get UID from an Angular fire store Document without snapshot

  28. 28

    How to remove a specific part of a text document without using range() python

  29. 29

    how to change document scroll speed in react without jquery

ホットタグ

アーカイブ