I'm trying to write a virtual graph mapping for a mongodb datasource in which the values of the json keys are having different pattern and I want to pick a substring from it as that substring would be used to create an IRI in BIND template. But, I'm facing issue while retrieving the mapped data.
I had attached the sample data demo, expected RDF, the virtual graph mapping file, the SPARQL Query, and the error.
Sample Mongodb json data from "mongo" collection:
{
"_id": "***************",
"boxID": "urn:abc:def:id:123456.98765432", # wanted to pick only 123456.98765432
"equipmentID": "http://www.equipment.com/id/12349876", # wanted to pick only 12349876
}
Wanted to create a Mapping that represents the data as the below RDF:
:12345698765432 a :Box ; :ID "12345698765432" .
:12349876 a :Equipment ; :ID "12349876" .
:12345698765432 :contains :12349876 .
Here is the mapping syntax which I created:
MAPPING
FROM JSON {
"mongo" : {
"_id" : "?id:objectId",
"$substr: ['$boxID', 15, -1]": "?boxID",
"$substr: ['$equipmentID', 27, -1]": "?equipmentID",
}
}
TO {
?boxNumber a :Box ;
:ID ?boxID .
?equipmentNumber a :Equipment ;
:ID ?equipmentID .
?boxNumber :contains ?equipmentNumber .
}
WHERE {
BIND (template("{boxID}") AS ?boxNumber)
BIND (template("{equipmentID}") AS ?equipmentNumber)
}
But, when I run the following SPARQL query to find the list of all Box IDs,
SELECT ?box
Where {
GRAPH <virtual://mongo_virtual_graph>
{
?box a :Box .
}
}
I face an Error for MongoDB query translation:
Failed to run query: com.complexible.stardog.plan.eval.operator.OperatorException: While running MongoDB query [{ $match : {"$substr: ['$boxID', 16, -1]" : {$exists : true, $ne : null}} },
{$project: {boxNumber: '$$substr: ['$boxID', 16, -1]'} }]
Here in the Error we can see that the MongoDB query for Project part is weird because it's having 2times $ before substr function $$substr.
Need help in how to resolve this mongodb use-case.
Thanks!