Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am very new to mathematica but it looks like an interesting language and I would like to explore it for a future project to create a web search engine. It seems like it would be fairly well suited for this as it seems to already be powering wolfram alpha.

I was wondering if the only databases you can hook into are SQL like databases. I can't see anywhere that talks about hooking into Mongo or a graph database like Neo4j. Why is this? Does this not make sense for some reason?

Any thoughts would be great. Thanks.


So ya. If you have examples of ways to connect Mathematica to MongoDB that would be awesome. If possible I would also like to see an example of connecting it to Neo4j. (Or reasons why that would not make sense). I guess I am wondering why everything for Mathematica is being used to connect to SQL databases thus far? Is there a reason for that?

share|improve this question
You can connect MongoDB to Mathematica but it is not as straight forward as using the built in SQL connectors. A possible advantage of Mongo, and possibly Couch and similar, is that in theory you should be able to access these from a free CDF. –  Mike Honeychurch Jan 19 at 22:17
If you re-word your question I'll dig up some MongoDB set up instructions and code and post later today. –  Mike Honeychurch Jan 19 at 22:28
Cool. Thanks. I updated it. Why are NoSQL databases less popular with Mathematica? And what about using a graph database like neo4j. The one way I was thinking of going about this could be using Clojuratica (call mathematica from clojure), and use clojure to access the database. –  user2433617 Jan 21 at 2:44
add comment

1 Answer

up vote 9 down vote accepted

Here are the two ways I have successfully used MongoDB with Mathematica. AFAIK much of this would also apply to similar DBs such as CouchDB.

A. Easy way

One working example used a third party Mongo supplier such as 28msec.io and use URLFetch e.g.

enter image description here

With this supplier you can both read from and write to the database using HTTP GET and simple query strings. While I have not tested it, it seems to me that you should be able to make calls to a set up such as this from a free CDF (it is my understanding that you can import from a URL from free CDF).

B. Stand alone implementation

I have installed MongoDB on my Mac and got it working with Mathematica using this method:

enter image description here

I do not imagine that the set up would be too different on other systems. To interface with Mathematica I have used the REST API. For me as a non-Java programmer this was far more straight forward than trying to make a JLink connector. I have no idea of performance issues of the REST API vs purpose built JLink connector. For the intended application there were no noticeable problems, slowdowns etc.

1 Download and install MongoDB.

2 Start the webserver

$ sudo apachectl start

3 Start Mongo DB

$ mongod --rest

4 Check that everything is working on port 28017

enter image description here

The problem with the install is that the bundled REST interface does not allow inserting etc. Full REST capabilities can be achieved with an external tool such as sleepy mongoose.

5 Install pymongo

$ easy_install pymongo

6 Download and install sleepy.mongoose.

You are now in business and can read from and write to your local MongoDB from Mathematica using URLFetch.

enter image description here


Forgot to mention that you use ImportString[ string, "JSON"] to convert the JSON to rules. Also forgot to mention that for easy option A, or similar database providers, if you can enter the login and password as part of the query string then you can use Import to read from, and write to, the database.

share|improve this answer
Wow this is awesome. Thanks! –  user2433617 Jan 21 at 21:32
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.