首页 > 解决方案 > 如何使用 GraphDB-MongoDB 集成?

问题描述

我想通过 GraphDB SPARQL 查询接口查询 MonboDB 实例。

目前,我在默认端口和同一主机上使用 GraphDB 8.9 Free 实例和 MongoDB 4.0.8,没有密码(没有端口对外开放)。我按照http://graphdb.ontotext.com/documentation/free/integrating-graphdb-with-mongodb.html的说明进行操作。

这是文档中的查询:

PREFIX cwork: <http://www.bbc.co.uk/ontologies/creativework/>
PREFIX inst: <http://www.ontotext.com/connectors/mongodb/instance#>
PREFIX : <http://www.ontotext.com/connectors/mongodb#>

SELECT ?creativeWork ?modified WHERE {
        ?search a inst:spb1000 ;
                :find '{"@graph.cwork:audience.@id" : "cwork:NationalAudience"}' ;
                :entity ?entity .
        GRAPH inst:spb1000 {
                ?creativeWork cwork:dateModified ?modified .
        }
}

创建索引显然是成功的:

[INFO ] 2019-04-05 14:01:53,036 [repositories/playground-default | c.o.g.s.StatementsController] POST SPARQL update request to repository
[INFO ] 2019-04-05 14:01:53,044 [repositories/playground-default | c.o.p.mongodb] Creating a new service in MongoDB: spb1000
[INFO ] 2019-04-05 14:01:53,045 [repositories/playground-default | c.o.p.mongodb] Setting connectionString for MongoDB service spb1000
[INFO ] 2019-04-05 14:01:53,045 [repositories/playground-default | c.o.p.mongodb] Setting database for MongoDB service spb1000
[INFO ] 2019-04-05 14:01:53,045 [repositories/playground-default | c.o.p.mongodb] Setting collection for MongoDB service spb1000

但是随后文档中的示例查询不起作用。GraphDB 输出 0 个结果,控制台显示以下消息:

[INFO ] 2019-04-05 14:02:13,158 [repositories/playground-default | c.o.f.s.RepositoryController] POST query -563697573
[ERROR] 2019-04-05 14:02:13,160 [repositories/playground-default | c.o.p.mongodb] iter not created yet
[ERROR] 2019-04-05 14:02:13,160 [repositories/playground-default | c.o.p.mongodb] iter not created yet
[ERROR] 2019-04-05 14:02:13,161 [repositories/playground-default | c.o.t.q.OwlimEvaluationStrategyImpl] Couldn't convert the query to our optimized model. Using sesame's query model
java.lang.NullPointerException: null
[...]

我应该得到超过 10 个结果,但目前我什么也没得到。似乎 GraphDB 无法生成 MongoDB 查询。由于我使用/复制了文档中的 SPARQL 查询,这应该是可能的。

标签: graphdb

解决方案


Because mongodb plugin doesn't present in 8.6 version of GraphDB when you upgrade to 8.9 version on start PluginManager detects that latter isn't in fingerprint and disables it to protect cluster integrity. First you should enable it using the following Sparql query:
"insert data { [] <http://www.ontotext.`com`/owlim/system#startplugin> "mongodb" }", 

afterwards you should create plugin into upgraded repository using query that is in the documentation or:

"PREFIX : <http://www.ontotext.com/connectors/mongodb#>
PREFIX inst: <http://www.ontotext.com/connectors/mongodb/instance#>
INSERT DATA {
    inst:spb1000 :service "mongodb://localhost:27017" ;
        :database "ldbc" ;
        :collection "creativeWorks" .
}"

you shouldn't delete the database or collection in MongoDB. 

推荐阅读