Integrating mongodb with neo4j, is there any API that will link them?

前端 未结 5 1777
故里飘歌
故里飘歌 2021-02-03 16:02

I am working on a recommendation engine. The user data is collected (Their friendship, locations, likes,education,...) and is already stored in mongodb. I need to recommend rel

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-03 16:47

    I found two ways to integrate mongodb and Neo4j. The first one was suggested by ryan1234 using Gremlin together with Gmongo. The steps are as following according to this excellent blog
    1- Download Gmongo and Java mongo driver
    2- copy the two jar files under neo4j/lib directory
    3- This is an example. suppose we have this collection (called follows) in mongodb

    { "_id" : ObjectId("4ff74c4ae4b01be7d54cb2d3"), "followed" : "1", "followedBy" : "3", "createdAt" : ISODate("2013-01-01T20:36:26.804Z") }
    { "_id" : ObjectId("4ff74c58e4b01be7d54cb2d4"), "followed" : "2", "followedBy" : "3", "createdAt" : ISODate("2013-01-15T20:36:40.211Z") }
    { "_id" : ObjectId("4ff74d13e4b01be7d54cb2dd"), "followed" : "1", "followedBy" : "2", "createdAt" : ISODate("2013-01-07T20:39:47.283Z") }
    

    from the Gremlin shell in Neo4j run the following commands.

    import com.gmongo.GMongo
    mongo = new GMongo() 
    db = mongo.getDB("local")
    db.follows.findOne().followed
    x=[] as Set; db.follows.find().each{x.add(it.followed); x.add(it.followedBy)}
    x.each{g.addVertex(it)}
    db.follows.find().each{g.addEdge(g.v(it.followedBy),g.v(it.followed),'follows',[followsTime:it.createdAt.getTime()])} 
    

    and that is it we have created the equivalent graph in neo4j

提交回复
热议问题