首页 文章

如何在Azure Cosmos DB中导入Graph数据库的数据? [关闭]

提问于
浏览
3

这些文档表明,只有在将数据导入Azure Cosmos DB以便与DocumentDB API一起使用而不是使用表API或图谱API时,才能使用数据迁移工具 . 那么,有没有办法从其他来源导入数据以在CosmosDB图形数据库中使用?

2 回答

  • 0

    通过下载Graph API演示项目,我 grab 了这种变化

    https://github.com/Azure-Samples/azure-cosmos-db-graph-dotnet-getting-started

    然后使用文本文件,手动构建查询:

    --INIT
    --g.V().drop()
    
    
    --CREATE
    ------
    --vertex
    g.addV('person').property('id', 'dave').property('firstName', 'Dave').property('lastName', 'Andersen').property('age', 49)
    g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39)
    --edge
    g.V('dave').addE('knows').to(g.V('mary'))
    
    
    --READ
    --filter
    --g.V().hasLabel('person').order().by('firstName', decr)
    --project
    --g.V().hasLabel('person').values('firstName')
    --traverse
    --g.V('thomas').outE('knows').inV().hasLabel('person')
    --loop
    --g.V('thomas').repeat(out()).until(has('id', 'robin')).path()
    --g.V().count()
    --g.E().count()
    
    
    --UPDATE
    --------
    --g.V('thomas').property('age', 44)
    
    
    --DELETE
    --dropedge
    --g.V('thomas').outE('knows').where(inV().has('id', 'mary')).drop()
    --dropvertex
    --g.V('thomas').drop()
    

    然后从代码中循环它:

    string queriesPath = AppDomain.CurrentDomain.BaseDirectory + "queries.txt";
    
                var queries = File.ReadAllLines(queriesPath).Where(l => !l.StartsWith("--") && !string.IsNullOrWhiteSpace(l));
    
                foreach (var query in queries)
                {
                    Console.WriteLine("Running " + query);
    
                    IDocumentQuery<dynamic> gremlinQuery = client.CreateGremlinQuery<dynamic>(graph, query);
                    while (gremlinQuery.HasMoreResults)
                    {
                        foreach (dynamic result in await gremlinQuery.ExecuteNextAsync())
                        {
                            Console.WriteLine($"\t {JsonConvert.SerializeObject(result)}");
                        }
                    }
    
                    Console.WriteLine();
                }
    
  • 0

    对于图形api,它取决于您使用的数据库 .

    • for neo4j有这个回购:https://github.com/bsherwin/neo2cosmos

    • 对于arangodb,我能够使用数据迁移工具将顶点和边集作为json上传,然后你可以编写一个简单的存储过程来连接连接顶点 .

    我被困在查询图集(这似乎不支持)的点上,所以我们可以上传同一集合中的边和顶点并使用脚本来制作边

相关问题