Introduction
AllegroGraph can query MongoDB databases using SPARQL. The interface is similar to what we provide for Solr and for the built-in free-text indexes.
Note that all of these indexes are orthogonal to triple indices like spogi
.
Interfacing with MongoDB
MongoDB ('mongo' is from "humongous") is a scalable, high-performance, open source NoSQL document based database. MongoDB provides JSON style document based storage with full text indexing, replication, sharding, MAP/REDUCE support and a rich document-based query language. It does not provide good support for complicated joins, linked data, graph analysis or rules.
By connecting AllegroGraph to MongoDB, it is possible to query graph style linked data and document based data in a single query.
Installing Apache MongoDB
MongoDB is not a Franz product. Setting up and maintaining a MongoDB database is a separate task and must be accomplished outside of AllegroGraph. See the MongoDB website for details.
In the rest of this document, we assume you have the MongoDB server installed and running on a computer you can access.
Important notes on running MongoDB with AllegroGraph
Please note the following:
The MongoDB database needs to be populated and maintained separately from adding triples to your triple-store. Adding and deleting data from one does not automatically synchronize with the other.
We use the Mongo ID as the linking variable between the two databases. This means that you need to add a triple like
ex:subject1001 <http://www.franz.com/hasMongoId> 4561
where 4561
is the MongoID for the information associated with ex:subject1001 in the MongoDB.
MongoDB connection settings
In order to connect to MongoDB, AllegroGraph needs to know five things:
the server where MongoDB is running,
the port on which MongoDB is listening,
the name of the database you are you using,
the name of the MongoDB collection you are using,
(optional unless you are using authentication) the username and password that will let you connect to the database.
These parameters can be set using AGWebView, the HTTP interface, or the Lisp interface, as we describe in this document.
The AGWebView interface
AGWebView is the browser-based interface to AllegroGraph. To use it with MongoDB, go to the Repository Overview page and click on the link under Store Control which says Manage external MongoDB connection
:
On the linked page, you can set the necessary Mongo parameters.
The HTTP interface
The AllegroGraph HTTP Protocol supports GET mongoParameters and POST mongoParameters. See The HTTP Protocol.
The Lisp interface
Use these Lisp functions to get and set these parameters:
Returns the current Mongo connection parameters in a property list.
Currently it contains these items:
:server
- The server name where MongoDB is running:port
- The port to use to communicate with MongoDB:database-name
- The name of the database to use when querying MongoDB:collection-name
- The name of the collection to use when querying MongoDB:user
- Used to authenticate to the Mongo DB server
Note, the :password from set-mongo-parameters is not returned.
Set MongoDB connection parameters.
You can set any combination of:
:server
:port
:database-name
:collection-name
- required to be non-empty:user
- optional:password
- optional
MongoDB and SPARQL 1.1
Once you have a MongoDB database set up and running and have added the linking triples to its associated AllegroGraph triple-store, you can query it using the SPARQL 1.1 query engine.
To query MongoDB with SPARQL, you use the magic predicates:
- <http://franz.com/ns/allegrograph/4.7/mongo/find>
An example query would look like:
prefix mongo: <http://franz.com/ns/allegrograph/4.7/mongo/>
prefix ex: <http://www.example.org#>
select * {
?s mongo:find 'medicate disastrous' .
?s ex:text ?text .
?s ex:otherProperty ?other .
}