Entity – How to retrieve I added to the ID of the document in the cosmosdb collection?

I have a collection and I insert different types of documents. I use the type parameter to distinguish the different data types in the collection. When I insert documents, I create one for each document Id field, but Cosmosdb has a built-in id field.

How to insert a new document in a query and retrieve the ID of the created document?

I think you only need the .getResource() method to get the created document obj.

< /p>

Please refer to the java code:

DocumentClient documentClient = new DocumentClient(END_POINT,
MASTER_KEY, ConnectionPolicy.GetDefault(),
ConsistencyLevel .Session);

Document document = new Document();
document.set("name","aaa");

document = documentClient.createDocument ("dbs/db/colls/coll",document,null,false).getResource();

System.out.println(document.toString());

//then do your business logic with the document.....

C# code:

Parent p = new Parent
{
FamilyName = "Andersen.1",
FirstName = "Andersen",
};

Document doc = client.CreateDocumentAsync("dbs/db/colls/ coll",p,null).Result.Resource;
Console.WriteLine(doc);

I hope it can help you.

< p>I have a collection, I insert different types of text File. I use the type parameter to distinguish different data types in the collection. When I insert documents, I create an Id field for each document, but Cosmosdb has a built-in id field.

How to insert a new document in a query and retrieve the ID of the created document?

I think you only need the .getResource() method to get the created document obj.

Please refer to the java code:< /p>

DocumentClient documentClient = new DocumentClient(END_POINT,
MASTER_KEY, ConnectionPolicy.GetDefault(),
ConsistencyLevel.Session);

Document document = new Document();
document.set("name","aaa");

document = documentClient.createDocument("dbs/db/colls/coll",document ,null,false).getResource();

System.out.println(document.toString());

//then do your business logic with the document. ....

C# code:

Parent p = new Parent
{
FamilyName = "Andersen.1",
FirstName = "Andersen",
};

Document doc = client.CreateDocumentAsync("dbs/db/colls/coll",p,null).Result.Resource;
Console.WriteLine(doc);

I hope it can help you.

Leave a Comment

Your email address will not be published.