What I want to do
I have some relational database tables (PostgreSQL) which I’m trying to convert to Dgraph.
There are two tables, author and books, and then a map table supporting a many-to-many relationship between the two tables.
I’m using the bulk loader to load the data.
I’m having problems getting the mapping to work in Dgraph.
What I did
I exported the authors and books table from DBeaver directly to JSON.
For the mapping table, in order to get the data into what I think is the right format, I exported the table to .csv and then ran the csv2json command per the documentation.
Here are snippets from each of the three JSON files:
Author:
{
"author_id" : "00004178-a951-4425-a260-40e548189169",
"full_name" : "Joe Johnson",
"dgraph.type" : "author"
}
Book:
{
"book_id" : "d6d30b03-27cf-4156-8b63-0218ff69a2bc",
"title" : "Awesome Book Title",
"date" : "2018-10-11",
"dgraph.type" : "book"
}
The mapping file, authored.json:
{
"uid": "_:00004178-a951-4425-a260-40e548189169",
"authored": {
"uid": "_:d6d30b03-27cf-4156-8b63-0218ff69a2bc"
}
}
The Authors and Books appear to load fine, but the “authored” predicate doesn’t seem to work and the following query comes back empty:
{
authors(func:has(authored), first: 5) {
full_name
authored {
expand(_all_)
}
}
}
If I run the following mutation, the above query will find Bugs Bunny as expected (but nothing else):
{
set {
_:7b100b59-6c99-473e-be52-eb00ec1ee631 <author_id> "7b100b59-6c99-473e-be52-eb00ec1ee631" .
_:7b100b59-6c99-473e-be52-eb00ec1ee631 <dgraph.type> "author" .
_:7b100b59-6c99-473e-be52-eb00ec1ee631 <full_name> "Bugs Bunny" .
_:7b100b59-6c99-473e-be52-eb00ec1ee631 <authored> _:25476291-e5a2-4867-bdba-ac09736323b0 .
_:25476291-e5a2-4867-bdba-ac09736323b0 <book_id> "25476291-e5a2-4867-bdba-ac09736323b0" .
_:25476291-e5a2-4867-bdba-ac09736323b0 <dgraph.type> "book" .
_:25476291-e5a2-4867-bdba-ac09736323b0 <title> "1,239 Ways to Cook a Carrot" .
}
}
Is there something wrong with the way I’m creating the authored.json?
Thanks in advance!