Getting multiple relationships and children of the same node - neo4j

Is it possible to get multiple 'children' nodes by relationship. For example, given the following query:
START event=node(4)
MATCH event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto
RETURN event, photoalbum, coverphoto
I thought it would be possible to also get the location of an event as follows:
START event=node(%i)
MATCH event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto, event-[:location]->location
RETURN event, photoalbum, coverphoto, location
However I just get an error saying they were expecting a RETURN type.
I have looked through the Cypher documentation but I can't seem to find anything on multiple MATCHes.

It turns out I only briefly read and therefore forgot about incoming/outgoing relationships. It just so happens that the location was an incoming relationship so wouldn't fetch. Instead of --> or <-- I am just using -- so the direction of relationship is generic.

You can try this one, it works fine with me
START event=node(%i)
MATCH location<-[:location]-event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto
RETURN event, photoalbum, coverphoto, location

Related

Exclude null values from GraphQL query

Disclaimer, I am still a noob in GraphQL.
Apologies for the long post, but I need to give as much information as possible to explain my issue.
I am currently trying to query my Neo4j using GraphQL and then tabulate the data using ReTool.
I managed to do most of the work but when I query the database, I also get the null values.
You can access the sandbox below to test yourself a probable solution.
https://codesandbox.io/s/great-marco-coy3k
The query I am using is the following:
query {
people{
child{
firstname{
name
}
middlename{
name
}
lastname{
name
}
phone{
name
}
email{
name
}
dob{
name
}
eid{
name
}
}
}
}
As you can see, I get back a mixture of null and none-null values.
What I would like to get back is the children that has data in them and ignore the null ones. The reason for that is when I try to populate my table, the null values appear there too.
I need to stress on the fact that I'd still need to retrieve "child" even if one or more of the objects are null as depicted in the image below:
While doing some research, I noticed that other people have the same problem I am facing (example), but most replies said there is no direct solution to this problem, many talked about adjusting the resolver which I am not sure how to do. The resolver file was already set by Neo4j Sandbox automatically and I don't know how to adjust it.
To provide more information regarding the root cause of the problem, you can check the Neo4j schema below:
As you can see, the two-person nodes that have the relationship MASTER_OF and CHILD_OF are similar.
When I query people{child{firstname name}...}
I get the value of the node that has a IN CHILD_OF relationship and null for the node that has IN MASTER_OF relationship.
As far as I understand, you are not sure what each value will return null : it may or it may not be null. In this case it is impossible to adjust your schema to only contain non-null values. You would have to deal with it in the frontend and completely exclude null values there.

contiki: uip_ds6_route_head() vs uip_ds6_route_lookup

Can anybody tell me the difference uip_ds6_route_head() vs uip_ds6_route_lookup(addr)?
I used to think that the uip_ds6_route_head() returned a route to every child (direct and indirect) for the node that calls the function. However, two nodes had a route to the same child (the r->ipaddr == r->nexthop)?
Thanks
Internally, uip-ds6-route.c keeps its routes in a list called routelist.
uip_ds6_route_head() simply returns the first element in the routelist.
uip_ds6_route_lookup(addr) will iterate over the routelist and return the best matching route for addr.

Graph Model: How to mark items in Neo4J as Read/Viewed

[EDITED]
I am trying to build an application that allows users to receive messages. The model looks something like this:
(user:Person)-[:HAS_MESSAGE]->(message:Message)
Multiple users can have the same message.
I am attempting to show this on the UI with the following query:
MATCH (user:Person)-[:HAS_MESSAGE]->(message:Message) WHERE user.EmployeeId = 'XYZ123' RETURN message
But on the UI, I want to indicate the messages that they have not yet seen.
What would be the best way to model this in the Neo4J? Should I use a Label or a property? Also, how do I update their read state in the same query?
Regards
Kiran
[EDITED]
Here is one approach.
When creating new Message nodes, assign false to a wasRead property on the HAS_MESSAGE relationship. Then, when you want to get unread messages (and, at the same time, mark them as having been read):
MATCH (user:Person)-[r:HAS_MESSAGE]->(message:Message)
WHERE user.EmployeeId = 'XYZ123' AND r.wasRead = false
SET r.wasRead = true
RETURN message
For better performance, you should consider creating an index on the Person/EmployeeId combination, like so:
CREATE INDEX ON :Person(EmployeeId)
Unfortunately, you cannot set indexes on relationships.

Neo4j Uniquness on update unique index value

The
uniqueness=create_or_fail
works great when creating a new node since it throws a 4xx response if a duplicate index key/value already exists.
However, if the node already exists and indexed and the indexed value needs to be updated, there is no way (that i am aware of) to update the value and fail if the new value already exists. That is because the Add Node to Index REST call does not throw a 4xx response if the new value already exists. as far as i can see the add node to index does not even participate in Uniqueness on indexes.
One solution is to delete the node and re-add it but this is not easy since all the other indexes and relationships on this node would have to be recreated.
another solution would be to add the Uniqueness parameter to the Add Node to Index REST call
http://docs.neo4j.org/chunked/1.9.M05/rest-api-indexes.html#rest-api-add-node-to-index
any other ideas on this?
thanks
I happened up on this question and here's what I figured out for a work-around.
During an update do as follows in a REST batch:
Delete all of node's index entries for the desired index
Create a new node using CreateOrFail on the desired index, except instead of using your normal properties just use a dummy property such as DeleteMe=true
Add the node to the desired index because if it got this far the previous step succeeded
Update node's properties
Use a Cypher statement to delete the dummy node Ex:
START n=node:index_name(index_key={value}) WHERE (n.DeleteMe!)=true DELETE n

How do I check for duplicates in event calendar eventkits

I fetched a list of all events and try to match it with my current events about to be added, but it never matches and just add duplicates.
The code I used to fetch is from apple's document. Can anyone help?
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingEvents.html#//apple_ref/doc/uid/TP40004775-SW1
Code from another tutorial (I scourged the net but couldn't find how to match events. the fetch predicates results title string comparison did not work)
http://neilang.com/entries/using-eventkit-in-ios/
I found out that one can save the eventstore event unique identifier immediately after saving. And with this identifier one can get the events back.

Resources