使用Gremlin和Azure Cosmos Graph在顶点中存储列表

时间:2018-03-22 14:08:22

标签: neo4j azure-cosmosdb graph-databases gremlin tinkerpop

我正在尝试存储Vertex本身对Vertex所做的更改列表。理想情况下我会想要这样的东西:

{
    "id": "95fcfa87-1c03-436d-b3ca-340cea926ee9",
    "label": "person",
    "type": "vertex",
    "log": [{
            "user": "user@user.dk",
            "action": "update",
            "timestamp": "22-03-2017",
            "field": "firstName",
            "oldValue": "Marco"
        }
    ]
}

使用此方法链我可以实现以下结构

graph.addV('person')
     .property('firstName', 'Thomas')
     .property(list, 'log', '22-03-2017')
     .properties('log')
     .hasValue('22-03-2017', '21-03-2017')
     .property('user','user@user.dk')
     .property('action', 'update')
     .property('field', 'firstName')
     .property('oldValue', 'Marco')
{
    "id": "95fcfa87-1c03-436d-b3ca-340cea926ee9",
    "label": "person",
    "type": "vertex",
    "properties": {
        "firstName": [{
                "id": "f23482a9-48bc-44e0-b783-3b74a2439a11",
                "value": "Thomas"
            }
        ],
        "log": [{
                "id": "5cfa35e1-e453-42e2-99b1-eb64cd853f22",
                "value": "22-03-2017",
                "properties": {
                    "user": "user@user.dk",
                    "action": "update",
                    "field": "firstName",
                    "oldValue": "Marco"
                }
            }
        ]
    }
}

然而,这似乎过于复杂,因为我必须存储一个值并为其添加属性 是否可以使用上述数据添加匿名对象(即没有idvalue)?

1 个答案:

答案 0 :(得分:0)

不是在历史记录日志中存储正确对象的实际解决方案,但如果您只是将其用作日志而不必通过其属性访问或查询它,那么您可以将序列化的JSON放入值中吗?

沿着这些线条的东西应该接近你要求的结构:

dynamic entry = new JObject();
entry.user = "user@user.dk";
entry.action = "update";
entry.timestamp = "22-03-2017 12:34:56";
entry.field = "firstName";
entry.oldValue = "Marco";

graph.addV('person')
     .property('firstName', 'Thomas')
     .property(list, 'log', entry.ToString());
{
    "id": "95fcfa87-1c03-436d-b3ca-340cea926ee9",
    "label": "person",
    "type": "vertex",
    "properties": {
        "firstName": [{
                "id": "f23482a9-48bc-44e0-b783-3b74a2439a11",
                "value": "Thomas"
            }
        ],
        "log": [{
                "id": "5cfa35e1-e453-42e2-99b1-eb64cd853f22",
                "value": "{\"user\":\"user@user.dk\",\"action\":\"update\",\"timestamp\":\"22-03-2017\",\"field\":\"firstName\",\"oldValue\":\"Marco\"}"
            }
        ]
    }
}

这些日志条目可以很容易地被读取,反序列化,使用和呈现,但对于可查询性不会有太大作用。