How to make multiple mongo collections works together with virtual graphs (sms)?

for ex:

my mongo have

collections:
  users
    _id: ?userId
    username: ?username

  groups
    _id: ?groupId
    name: ?groupName
    parentGroupId: ?groupId

  groupmembers
    _id: doesn't matter
    groupId: ?groupId
    userId: ?userId

i'm trying to write something like this and click save, but an error

"JSON template must contain a single key indicating the MongoDB document collection"

PREFIX : <http://kim.jong.un/onto#>

MAPPING
FROM JSON {
    "users": {
        "_id": "?userId",
        "username": "?username",
        "role": "?role"
    },
    "groupmembers": {
        "_id": "?groupMemberId",
        "groupId": "?groupId",
        "userId": "?userId"
    }
}
TO {
    ?user a :User;
        :username ?username;
        :role ?role .
}
WHERE {
    BIND (template("http://kim.jong.un/onto#{userId}") AS ?user)
    BIND (template("http://kim.jong.un/onto#{groupMemberId}") AS ?groupmember)
}

it looks we have a video for sql

if i follow the syntax from video

the relation description should put into separate sms block like

MAPPING
FROM {}
TO {}
WHERE {}

MAPPING
FROM {}
TO {}
WHERE {}

MAPPING
FROM {}
TO {}
WHERE {}

MAPPING
FROM {}
TO {}
WHERE {}

but i still can't figure out how to make it works.
the primary key and foreign key variable looks scoped if its not write in same block
how to indicate its same key(field, ?variable)

my excepted sparql result is like

(user.username)._id <- userId groupId -> (group.Id).name
[username] [groupName]
:jess :stardog

Each collection should be in a separate mapping. It will look something like this:

PREFIX : <http://kim.jong.un/onto#>

# This mapping declares how the user entries correspond to User entities in the RDF graph                                                                                                                                                                                                                                                                                   
MAPPING <urn:users>
FROM JSON {
    "users": {
        "_id": "?userId",
        "username": "?username",
        "role": "?role"
    }
}
TO {
    ?user a :User;
        :username ?username;
        :role ?role .
}
WHERE {
    BIND (template("http://kim.jong.un/onto#{userId}") AS ?user)
}
;
# This mapping creates a node for each "group membership" pointing to the                                                                                                                                                                                                                                                                                                   
# user and group in which it is a member. There will presumably be another                                                                                                                                                                                                                                                                                                  
# mapping with details of the group                                                                                                                                                                                                                                                                                                                                         
MAPPING <urn:groupmembers>
FROM JSON {
    "groupmembers": {
        "_id": "?groupMemberId",
        "groupId": "?groupId",
        "userId": "?userId"
    }
}
TO {
  ?groupmember :hasUser ?user
    :hasGroup ?group
}
WHERE {
    BIND (template("http://kim.jong.un/onto#{userId}") AS ?user)
    BIND (template("http://kim.jong.un/onto#{groupId}") AS ?group)
    BIND (template("http://kim.jong.un/onto#{groupMemberId}") AS ?groupmember)
}
# You can query this like: ?user a :User ; ... . ?groupmember :hasUser ?user ; :hasGroup ?group
1 Like

awesome!!!
this is mind blowing!!! :boom:
you people are making black magic ... :alien: :alien: :alien:

1 Like

Glad you like it. Keep in touch.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.