Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j : best alternative to storing nested properties?

Tags:

json

nested

neo4j

I have an existing live neo4j db with relationships like this...

User-[:Owner]->Item

User contains the usual properties; name, email etc.
Owner relationship has created_on property
Item has a bunch of properties about the item; title, description etc.

I want to add in a geo-location property for the Item. This will be a latitude and longitude of where the user created the item.

A JSON api is serving up this data to our clients. The API will merge some of the data, so an Item object in the api will have a nested User object as a property of it...

"item": {
   "title":"my item",
   "user":{
        "name":"smith"
   }
}

And I was initially thinking the location would follow suit...

"item": {
   "title":"my item",
   "user":{
        "name":"smith"
   },
   "geo_position":{
       "latitude":"10.123456789",
       "longitude":"10.123456789" 
   }
}

As we cant nest data in Neo, was wondering how to store this data...

  1. JSON serialise the latitude and longitude data under a geo_position property of the Item ?
  2. As properties of the relationship Owner.latitude?
  3. As a new Node ? Location `User-[:owns]->Mite<-[:created_at]-Location?
  4. As individual properties of the Item so not nested, item.latitude ?

1 - I assume we cant query.
2 - doesn't feel like the right place.
3 - its extremely unlikely 2 Items will have the same location as lat long is very precise, so almost No Items will share this node, so is it really a node?

So is 4 really the way to do it, and just not nest them ?

m

like image 245
Matt Bryson Avatar asked Apr 20 '16 12:04

Matt Bryson


People also ask

What is the use of property files in Neo4j?

property* Stores the key/value properties from your database label* Stores index related label data from your graph Since Neo4j is a schema-less database, we use fixed record lengths to persist data and follow offsets in these files to know how to fetch data to answer queries.

What do you consider when considering alternatives to Neo4j?

Considering alternatives to Neo4j? See what Cloud Database Management Systems Neo4j users also considered in their purchasing decision. When evaluating different solutions, potential buyers compare competencies in categories such as evaluation and contracting, integration and deployment, service and support, and specific product capabilities.

Is Neo4j the best graph database?

* Neo4j by itself is the leading graph database. If what you need is a pure graph database it is a pretty good option. * ArangoDB and OrientDB are the next ones on the list. These are multimodel graph databases that can be useful if you need Graph + JSON documents + SQL. Don't focus too much on benchmarks comparing them performance to Neo4j.

Can I use BLOB data In Neo4j?

Using BLOB data in Neo4j is one of the very few real anti-patterns for graph databases, in my opinion. If you have to deal with BLOB data, choose an appropriate store for that use case and use Neo4j to store the URL that points you to the binary data.


1 Answers

You own analysis is basically correct. I would go with number 4.

Here is more about why number 2 is not a good idea. Logically: the location of an item belongs in that item's node, not in a particular relationship to it. Practically: if the object changed ownership you should not have to copy its location to a new relationship, and querying for an item's location should be as quick and simple as just getting its node.

like image 103
cybersam Avatar answered Sep 23 '22 21:09

cybersam