Table of Contents

Introduction

Interfacing with MongoDB

Installing Apache MongoDB

Important notes on running MongoDB with AllegroGraph

MongoDB connection settings

The AGWebView interface

The HTTP interface

The Lisp interface

MongoDB and SPARQL 1.1

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:

MongoDB connection settings

In order to connect to MongoDB, AllegroGraph needs to know five things:

  1. the server where MongoDB is running,

  2. the port on which MongoDB is listening,

  3. the name of the database you are you using,

  4. the name of the MongoDB collection you are using,

  5. (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:

WebView link to MongoDB

On the linked page, you can set the necessary Mongo parameters.

WebView Mongo page

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:

get-mongo-parameters &key  db
function

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-mongo-parameters &rest  args  &key  db  port  server  database-name  collection-name  user  password
function

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:

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 .  
}