我有一个集合,我插入不同类型的文档.我使用type参数来区分集合中的不同数据类型.当我插入文档时,我为每个文档创建了一个Id字段,但Cosmosdb有一个内置的id字段. 如何在一个查询中插入
如何在一个查询中插入新文档并检索所创建文档的ID?
我认为你只需要.getResource()方法来获取创建文档obj.请参考java代码:
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#代码:
Parent p = new Parent { FamilyName = "Andersen.1", FirstName = "Andersen", }; Document doc = client.CreateDocumentAsync("dbs/db/colls/coll",p,null).Result.Resource; Console.WriteLine(doc);
希望它能帮到你.