Insert multiple vertices at once using the Cosmos DB Graph-API

I want to quickly insert multiple vertices using the Azure Cosmos DB Graph-API. Most current Microsoft samples create vertices one by one and execute a Gremlin request for each, for example:

IDocumentQuery<dynamic> query = client.CreateGremlinQuery<dynamic>(graph, "g.addV('person').property('id', 'thomas').property('name', 'Thomas').property('age', 44)");

while (query.HasMoreResults)
{                    
    foreach (dynamic result in await query.ExecuteNextAsync())  {   
        Console.WriteLine($"\t {JsonConvert.SerializeObject(result)}"); 
    }
    Console.WriteLine();
}


query = client.CreateGremlinQuery<dynamic>(graph, "g.addV('person').property('id', 'mary').property('name', 'Mary').property('lastName', 'Andersen').property('age', 39)");

while (query.HasMoreResults)
{                    
    foreach (dynamic result in await query.ExecuteNextAsync())  {   
        Console.WriteLine($"\t {JsonConvert.SerializeObject(result)}"); 
    }
    Console.WriteLine();
}

However, this is less than ideal when I want to create a couple of thousand vertices and edges to initially fill out the graph, as this may take some time.

This is with the Microsoft.Azure.Graphs v0.2.0-preview library

How can I effectively add multiple vertices to the Cosmos database at once so that I can use the Graph API syntax later?

+4
source share
2 answers

, - Document API. , 5500+ / . , , Cosmos , . API gremlin, , Azure SELECT * FROM c.

ORM, , POCOs , . , , , Nuget . , , , .

+4

, CosmosDB 100% TinkerPop, - , gremlin script, .

:

g.addV('person').property('id', 'mary').property('name', 'Mary').property('lastName', 'Andersen').property('age', 39)

:

g.addV('person').property('id', 'mary').property('name', 'Mary').property('lastName', 'Andersen').property('age', 39); g.addV('person').property('id', 'david').property('name', 'David').property('lastName', 'P').property('age', 24);

.. ..

gremlin script Groovy, , ..

+1

Source: https://habr.com/ru/post/1678427/


All Articles