使用 timestamp() 作为值时更新关系 属性
Update relationship property when using timestamp() as value
我有这段代码,它很棒,但正如您将看到的那样,它添加了与项目的每个单独视图的新关系。
return client.Cypher
.Match("(p:Person)", "(s:Store)")
.Where((Person p) => p.Email == username)
.AndWhere((Store s) => s.Name == store)
.Merge("(product:Product { pId: {pId} })")
.OnCreate()
.Set("product = {newProduct}")
.WithParams(new
{
pId = newProduct.pId,
newProduct
})
.CreateUnique("product-[:STOCK_FROM]->s")
.CreateUnique("(p)-[b:BROWSED{timestamp:timestamp()}]->(s)")
.CreateUnique("(p)-[v:VIEWED{timestamp:timestamp()}]->(product)")
.Return<Product>("product").Results.ToList();
现在理想情况下,我想添加第二个名为 total 的属性,它是一个 int。此属性将随着每次访问而递增,时间戳将更新为 'lastviewed',例如:
.Create("(p)-[b:BROWSED{lastviewed:timestamp(),total:1}]->(s)")
.Create("(p)-[v:VIEWED{lastviewed:timestamp(),total:1}]->
但我不确定两件事...
1.如何查询关系是否已经存在,我想应该是这样的:
.Match("(p:Person)-[:BROWSED]-(product)")
.Where((Person p) => p.Email == username)
但是如果我在 .OnCreate 之后 运行 这样做,我会遇到需要使用 .With() 的错误,这让我陷入困境,但我离题了..
- 查询后,如何增加total属性的数据值?
问题是我在这里看到了来自不同版本的客户端和不同版本的 Neo4j 的答案,我在 2.2.3 上使用最新的客户端(今天下载)。
有人请帮忙! :)
无法将其放入评论中,因此我将在此处更新:
return client.Cypher
.Match("(p:Person)", "(s:Store)")
.Where((Person p) => p.Email == username)
.AndWhere((Store s) => s.SearchIndex == store)
.Merge("(product:Product { ASIN: {ASIN} })")
.OnCreate()
.Set("product = {newProduct}")
.WithParams(new
{
ASIN = newProduct.ASIN,
newProduct
})
.CreateUnique("product-[:STOCK_FROM]->s")
.Merge("(p)-[b:BROWSED]->(s)")
.OnCreate()
.Set("b.lastviewed=timestamp(), b.total=1")
.OnMatch()
.Set("b.lastviewed=timestamp(), b.total=b.total+1")
.Return<Product>("product").Results.ToList();
完美:)
我会使用 MERGE
和 ON CREATE SET
以及 `ON MATCH SET``
MERGE (p)-[b:BROWSED]->(s)
ON CREATE SET b.total = 1
ON MATCH SET b.lastviewed=timestamp(), b.total=b.total+1
不确定 Neo4jClient 中的 MERGE 支持有多好
或者如果您想继续使用 CREATE
CREATE UNIQUE (p)-[b:BROWSED]->(s)
SET b.total = coalesce(b.total,1)+1, b.lastviewed=timestamp()
我有这段代码,它很棒,但正如您将看到的那样,它添加了与项目的每个单独视图的新关系。
return client.Cypher
.Match("(p:Person)", "(s:Store)")
.Where((Person p) => p.Email == username)
.AndWhere((Store s) => s.Name == store)
.Merge("(product:Product { pId: {pId} })")
.OnCreate()
.Set("product = {newProduct}")
.WithParams(new
{
pId = newProduct.pId,
newProduct
})
.CreateUnique("product-[:STOCK_FROM]->s")
.CreateUnique("(p)-[b:BROWSED{timestamp:timestamp()}]->(s)")
.CreateUnique("(p)-[v:VIEWED{timestamp:timestamp()}]->(product)")
.Return<Product>("product").Results.ToList();
现在理想情况下,我想添加第二个名为 total 的属性,它是一个 int。此属性将随着每次访问而递增,时间戳将更新为 'lastviewed',例如:
.Create("(p)-[b:BROWSED{lastviewed:timestamp(),total:1}]->(s)")
.Create("(p)-[v:VIEWED{lastviewed:timestamp(),total:1}]->
但我不确定两件事... 1.如何查询关系是否已经存在,我想应该是这样的:
.Match("(p:Person)-[:BROWSED]-(product)")
.Where((Person p) => p.Email == username)
但是如果我在 .OnCreate 之后 运行 这样做,我会遇到需要使用 .With() 的错误,这让我陷入困境,但我离题了..
- 查询后,如何增加total属性的数据值?
问题是我在这里看到了来自不同版本的客户端和不同版本的 Neo4j 的答案,我在 2.2.3 上使用最新的客户端(今天下载)。
有人请帮忙! :)
无法将其放入评论中,因此我将在此处更新:
return client.Cypher
.Match("(p:Person)", "(s:Store)")
.Where((Person p) => p.Email == username)
.AndWhere((Store s) => s.SearchIndex == store)
.Merge("(product:Product { ASIN: {ASIN} })")
.OnCreate()
.Set("product = {newProduct}")
.WithParams(new
{
ASIN = newProduct.ASIN,
newProduct
})
.CreateUnique("product-[:STOCK_FROM]->s")
.Merge("(p)-[b:BROWSED]->(s)")
.OnCreate()
.Set("b.lastviewed=timestamp(), b.total=1")
.OnMatch()
.Set("b.lastviewed=timestamp(), b.total=b.total+1")
.Return<Product>("product").Results.ToList();
完美:)
我会使用 MERGE
和 ON CREATE SET
以及 `ON MATCH SET``
MERGE (p)-[b:BROWSED]->(s)
ON CREATE SET b.total = 1
ON MATCH SET b.lastviewed=timestamp(), b.total=b.total+1
不确定 Neo4jClient 中的 MERGE 支持有多好
或者如果您想继续使用 CREATE
CREATE UNIQUE (p)-[b:BROWSED]->(s)
SET b.total = coalesce(b.total,1)+1, b.lastviewed=timestamp()