MongoDb: Using a graph as a database to search for "friends", for example, "friends"?

I am studying a graph database and I found neo4j, and although this seems perfect, I also came across mongodb.

Mongodb is not an official charting base, but I wondered if it can be used for my scenerio?

I am writing an application in which users can have friends, and these friends can have friends, etc. A typical social part of a social network.

I was wondering in my situation maybe mongodb?

How easy would it be to implement or do I really need to focus on the db. REAL graph?

I notice that foursquare uses mongodb, so I assume it supports the infrastructure.

But how easy it would be to find all the friends of my friends who also have friends in the commune - for example

Any help really appreciated here.

+6
source share
2 answers

Although this would not be possible, MongoDB is not suitable for this scenario.

The reason is that MongoDB does not do JOINs. When you need a query that spans multiple documents, you need a separate query for each document.

In your example, each user document will have an array with the _id their friends. To find "all friends of UserA friends who are also UserB friends", this would mean that you:

  • find userA and get his friends array
  • find all users in this array and get their friendly arrays
  • find all users in these arrays that have UserB in their friends array

These are the three queries you must complete. Between each of these queries, a result set should be sent to the application, the application should formulate a new query and send it back to the database. The result returned from the second query can be quite large, which means that the third query can take some time.

tl; dr: Use the right tool for the job. When your data is graph-based and you want to run graph-based queries on it, use the graph database.

+6
source

You probably need the actual graph database, not MongoDB. Try using the TinkerPop graphics technology stack to get started. Using Blueprints (which is similar to JDBC for graphs), you can see the performance of MongoDB as a graph (using Blueprint Compo MongoDB ) against Neo4j , Titan, or any number of other graphs.

+1
source

Source: https://habr.com/ru/post/954163/


All Articles