2017-07-05 11 views
0

したがって、私はorient 2.0.0 dbを持っています。これをdbcosmos dbに移動したいと思います。私が使用している技術は.Netなので、javaと他の豊富なドライバは使用できません。

私が移行中に直面している主な問題は、私の向きの頂点がオブジェクトであるプロパティを含んでいることです。したがって、gremlinクエリを使用してcosmos dbにオブジェクトをプロパティとして追加する方法があります。

gremlinのtinkerpop docおよびAzure Cosmos DB Docsの例は、すべてシンプルなデータ型を追加していることを示しています。gremlinクエリを使用してオリエント頂点をCosmos DBに移行する

答えて

1

私が知る限り、プロパティは現在、cosmos dbへのgremlinクエリを使用してサポートされていないため、オブジェクトを追加してください。

私の仕事場は、オブジェクトをフラットにできることです。私はテストデモを書いた、あなたはそれに論理を追加することができます。セクションをpackages.configをご参照ください1.Create C#プロジェクト

とMicrosoft.Azure.Graphs SDK、詳細を追加します。

次は私の詳細手順です。プロジェクトへ

2.Addカスタムクラス

public class Custom 
    { 
     public string Type { get; set; } 
     public string Name { get; set; } 
    } 

3. 4.Add RunAsync機能

public static string CovertToGremlinString(object pObject,string type) 
     { 
      var propertyList = new List<string>(); 
      // var dic = new Dictionary<string, string>(); 
      if (pObject == null) return null; 
      var jobject = JObject.FromObject(pObject); 
      propertyList.AddRange(pObject.GetType().GetProperties().Select(prop => prop.Name)); 
      var s = propertyList.Aggregate($"g.addV('{type}')", (current, property) => current + $".property('{property}','{jobject[property]})')"); 
      // dic.Add(type, s); 
      return s; 
     } 

グレムリン文字列に隠れたオブジェクトに機能を追加し、我々はまた、デモを得ることができますAzureポータルのコード

public async Task RunAsync(DocumentClient client) 
    { 
     Database database = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = "graphdb" }); 

     DocumentCollection graph = await client.CreateDocumentCollectionIfNotExistsAsync(
      UriFactory.CreateDatabaseUri("graphdb"), 
      new DocumentCollection { Id = "Custom" }, 
      new RequestOptions { OfferThroughput = 1000 }); 

     // Azure Cosmos DB supports the Gremlin API for working with Graphs. Gremlin is a functional programming language composed of steps. 
     // Here, we run a series of Gremlin queries to show how you can add vertices, edges, modify properties, perform queries and traversals 
     // For additional details, see https://aka.ms/gremlin for the complete list of supported Gremlin operators 
     var custom = new Custom 
     { 
      Name = "Tom", 
      Type = "1" 
     }; 
     var s = CovertToGremlinString(custom, "custom"); 
     Dictionary<string, string> gremlinQueries = new Dictionary<string, string> 
     { 
      {"Cleanup", "g.V().drop()"}, 
      {"AddVertex 1", s} 
     }; 

     foreach (KeyValuePair<string, string> gremlinQuery in gremlinQueries) 
     { 
      Console.WriteLine($"Running {gremlinQuery.Key}: {gremlinQuery.Value}"); 


      // The CreateGremlinQuery method extensions allow you to execute Gremlin queries and iterate 
      // results asychronously 
      IDocumentQuery<dynamic> query = client.CreateGremlinQuery<dynamic>(graph, (string) gremlinQuery.Value); 
      while (query.HasMoreResults) 
      { 
       foreach (dynamic result in await query.ExecuteNextAsync()) 
       { 
        Console.WriteLine($"\t {JsonConvert.SerializeObject(result)}"); 
       } 
      } 

      Console.WriteLine(); 
     } 

5.ローカルでテストしてください。詳細については、

string endpoint = ConfigurationManager.AppSettings["Endpoint"]; 
    string authKey = ConfigurationManager.AppSettings["AuthKey"]; 

    using (DocumentClient client = new DocumentClient(
       new Uri(endpoint), 
       authKey, 
       new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp })) 
      { 
       Program p = new Program(); 
       p.RunAsync(client).Wait(); 
      } 

enter image description here

packages.config

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="Microsoft.Azure.DocumentDB" version="1.14.0" targetFramework="net452" /> 
    <package id="Microsoft.Azure.Graphs" version="0.2.0-preview" targetFramework="net452" /> 
    <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net452" /> 
    <package id="Microsoft.CodeAnalysis.Common" version="1.3.0" targetFramework="net452" /> 
    <package id="Microsoft.CodeAnalysis.CSharp" version="1.3.0" targetFramework="net452" /> 
    <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" /> 
    <package id="System.Collections" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Collections.Immutable" version="1.1.37" targetFramework="net452" /> 
    <package id="System.Diagnostics.Debug" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Globalization" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Linq" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Reflection.Metadata" version="1.2.0" targetFramework="net452" /> 
    <package id="System.Resources.ResourceManager" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Runtime" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Runtime.Extensions" version="4.0.0" targetFramework="net452" /> 
    <package id="System.Threading" version="4.0.0" targetFramework="net452" /> 
</packages> 
+0

おかげで、私は、オブジェクトがサポートされていなかったことを知りませんでした。私がcosmos dbへの移行を続けることを決めたら、あなたのヒントを使用しようとします。 –

関連する問題