I'm trying to seed a neo4j with data from a mongodb using apoc. The idea is to first create a kindof 1-1 mirror of the mongo db and then replace the key-based mapping with relations. I'm having troubles with ObjectId's which are extensively used as the main means for relations (PK/FK):
{
"_id" : ObjectId("50db1341c2e638a3ebef2404"),
"parent" : ObjectId("50db12c2c2e638a3ebef2401"),
"referralDensityInfo" : ObjectId("50db12c2c2e638a3ebef2401"),
"unitInfo" : [ ],
"plural" : "Röda paprikor",
"singular" : "Röd paprika",
"referralUnitInfo" : [
{
"reference" : ObjectId("50db12c2c2e638a3ebef2401"),
"unit" : ObjectId("508e86f6c2e60ff9d423e293")
}
],
"dataSourceNutritionInfo" : ObjectId("507aa464c2e631891c0d9046"),
"referralNutritionInfo" : ObjectId("50db12c2c2e638a3ebef2401"),
"preferredName" : "Röd paprika",
"searchWords" : [
""
]
}
First try was just using:
CALL apoc.mongodb.get('mongodb://host.docker.internal:5700','kostbevakningen','ingredients', {})
Cannot convert org.bson.types.ObjectId to AnyValue
Then I found this little clue:
So now calling:
CALL apoc.mongodb.get('mongodb://host.docker.internal:5700','kostbevakningen','ingredients', {}, true)
I get a bunch of data and it seems to work so far. However, when trying to use the values:
CALL apoc.mongodb.get('mongodb://host.docker.internal:5700','kostbevakningen','ingredients', {}, true) YIELD value as mongo_i
MERGE (i: Ingredient {_id: mongo_i._id})
SET i += {
parent: mongo_i.parent,
dataSourceNutritionInfo: mongo_i.dataSourceNutritionInfo
};
Property values can only be of primitive types or arrays thereof
So I guess there is something I'm missing in the puzzle still to be able to use these ObjectId's.
I have the jar's I'm supposed to have I think:
# ls -l plugins
total 15840
-rwxrwxrwx 1 neo4j neo4j 2217 Aug 22 11:27 README.txt
-rw------- 1 neo4j neo4j 13749813 May 31 11:12 apoc-3.5.0.4-all.jar
-rw-r--r-- 1 root root 494021 Aug 13 11:06 bson-3.11.0.jar
-rw-r--r-- 1 root root 374817 Aug 13 11:43 mongodb-driver-3.11.0.jar
-rw-r--r-- 1 root root 1435219 Aug 13 11:25 mongodb-driver-core-3.11.0.jar
-rw-r--r-- 1 root root 152721 Aug 13 11:34 mongodb-driver-sync-3.11.0.jar
There seems to be some effort to handle Id's here:
but this seems to just handle the object primary key "_id", not any foreign key references to such a primary key which I guess is why I'm having problems.
Can I hook my own serializer in there somewhere? I would like to stick a toString()
there on my keys and I would be fine I guess, but now it's just choking…