harry-potter
harry-potter

Reputation: 2049

MongoDB vs Neo4j query

I'm comparing two NOSQL DBMS: MongoDB vs Neo4j. In these databases I have some football teams with information about common name, official name, country, stadium, uniform, ecc...
In MongoDB the attribute uniform is an array that contains the colours of the uniform.
In Neo4j each colour is a node with a tone property. UNIFORM is the arc that associates a team to a uniform colour.
I made the same query on both of them and I want to evaluate the performance: the query is to find the common_name of all teams that have in their uniform green tone. enter image description here

Now, can I say that this query is more efficient in Neo4j than in MongoDB? I thought that in MongoDB I have to scan for each document the array uniform. Instead in Neo4j I have to visit the graph. I can't use the cursor.explain("executionStats") in MongoDB to see the executionTimeMillis because in my DB there are too few documents, but in Neo4j the query takes 25 ms.

Upvotes: 0

Views: 1488

Answers (1)

Brian Underwood
Brian Underwood

Reputation: 10856

You should certainly have more documents to test. But a few things:

Firstly, you should have an index in Neo4j if you don't already.

CREATE INDEX ON :colour(tone)

That should allow Neo4j to find the node that you're looking for and then quickly browse to the appropriate Team nodes. The standard for Neo4j labels, by the way, is UpperCaseFirstCamelCase. See: http://nigelsmall.com/zen

Secondly, this is a small example of why it can be hard to compare databases with different paradigms. In MongoDB you're representing colors (or colours ;) as a property, but in Neo4j you're representing it as a separate node. That's not really the same thing as in MongoDB you have one entity and in Neo4j you have two. In Neo4j you could also use a property on the Team nodes and just have your index there.

The thing is that MongoDB doesn't have a concept of joins/relationships. So if you tried having a colours table then you're going to have more difficulty with Mongo. I'd suggest having a larger domain model spanning at least 5-10 entities so that you can better compare. You should especially thing about ways in which you might want to query/aggregate across entities.

If you'd like help getting a better feel for how to model in Neo4j, there's now a public users' Slack group with a modeling channel for help with such things.

Upvotes: 3

Related Questions