是否有控制属性顺序的机制?
我无法在 http://www.neo4j.org/console 中复制它
如果我执行以下操作,则使用 Neo4j 1.9.2 社区:
CREATE (m1 {`$type`: {moduleTypeName}, Name: 'M1', ModelNumber: 'MN1'})
然后我使用我返回的 REST 密码端点从密码查询中取回此节点...
{
"extensions": {},
"paged_traverse": "http://localhost:7575/db/data/node/3777/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships": "http://localhost:7575/db/data/node/3777/relationships/out",
"traverse": "http://localhost:7575/db/data/node/3777/traverse/{returnType}",
"all_typed_relationships": "http://localhost:7575/db/data/node/3777/relationships/all/{-list|&|types}",
"property": "http://localhost:7575/db/data/node/3777/properties/{key}",
"all_relationships": "http://localhost:7575/db/data/node/3777/relationships/all",
"self": "http://localhost:7575/db/data/node/3777",
"properties": "http://localhost:7575/db/data/node/3777/properties",
"outgoing_typed_relationships": "http://localhost:7575/db/data/node/3777/relationships/out/{-list|&|types}",
"incoming_relationships": "http://localhost:7575/db/data/node/3777/relationships/in",
"incoming_typed_relationships": "http://localhost:7575/db/data/node/3777/relationships/in/{-list|&|types}",
"create_relationship": "http://localhost:7575/db/data/node/3777/relationships",
"data": {
"ModelNumber": "MN1",
"$type": "ModuleType",
"Name": "M1"
}
}
我正在使用 http://james.newtonking.com/pages/json-net.aspx要解析 JSON 并自动推断对象类型,$type 属性必须放在首位。当您不想先将整个内容加载到内存中时,在流中解析 JSON 时这样做很有意义。
它似乎不是按字母顺序排列的,而且似乎也不是随机的。看起来顺序对于不同的对象类型是一致的,但它们之间不一致。
我也在 Shell 中拉取了节点,因此顺序似乎不取决于我如何获取节点,但也与我创建节点的顺序无关。
最佳答案
属性没有保证顺序。不要对“可能”排序做出任何假设。即将推出的版本可能会改变这种假定的行为并破坏您的代码。
我想在 Cypher 中不返回节点本身以支持属性列表更简单,例如
START node=node(<myid>)
RETURN node.`$type`, node.ModelNumber, node.Name
这已经定义了列。
关于neo4j - Neo4j 属性顺序可以控制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18318491/