Group Abstract Group Abstract

Message Boards Message Boards

5
|
32.4K Views
|
18 Replies
|
20 Total Likes
View groups...
Share
Share this post:

MongoDB and Mathematica

Posted 13 years ago
Hi everyone,

I'm looking for a database link between Mathematica and MongoDB. Is it possible? I see nothing about this in the DatabaseLink reference. Any ideas?

Steeve
POSTED BY: Steeve Brechmann
18 Replies

Hello all. Is there support for "Change Streams" in MongoLink?

https://www.mongodb.com/docs/manual/changeStreams/

I would like to monitor for changes in a MongoDB database within Mathematica. I am currently able to do so with CouchDB because it uses an open standard that runs over http (EventSource) but I am evaluating moving to MongoDB which seems to only provide this functionality via its driver.

POSTED BY: Gustavo Delfino

That's cool! Thanks for sharing this new feature.

POSTED BY: Rodrigo Murta
POSTED BY: Sérgio Carvalho

From the MongoLink Tutorial, applying the format suggested in the section "Modifying Documents" suggests this is the correct syntax:

MongoCollectionFind[coll, <|"Age" -> <|"$gt" -> 30|>|>
POSTED BY: Robert Ferguson
POSTED BY: Sérgio Carvalho

This works with mathematica objects (arrays, lists) and with Map for instance but i can't figure out how to use it in cursor objects.

If you are doing a MongoDB query, then Mathematica functions (like ToExpression) definitely not supported. The issue is then a MongoDB issue, and there are various options you have (eg see this https://stackoverflow.com/questions/18039358/mongodb-gt-lt-operators-with-prices-stored-as-strings)

POSTED BY: Sérgio Carvalho

If the solution to this trivial problem is to convert the source of the data (defeating a little bit the idea of NoSQL way of thinking)

That is the correct solution if you intend to represent this data in any database and perform database-native queries on the data. NoSQL does not imply 'no types for fields', just no fixed schema.

Indeed but couldn't it be different in future versions of WM?

How so? How can MongoLink change the behaviour of the MongoDB $gt operator?

Again, Thank you for your reply. I know MongoLink has to work with the behaviors inherit by MongoDB, but why not create a new function (e.g, named MongoCollectionFindType(coll, {query, typeexpect} )) in which the user say what kind of data it expects to find in the query and if some documents have different types of the expected the function does that conversion in order to make the comparison...and of course this new function does not return a cursor of the documents matching the query, it has to return a list of some sort (maybe not all "columns" but only some chosen by the user), but with the advantage of already having converted to the "typeexpected". Other "problem" is the fact that you, after getting a cursor of the documents return by a MongoFindCollection query, cannot use it as a first argument of a new MongoFindCollection.....refining the query and not handling the data just yet. I'm sorry if i'm not making sense.

POSTED BY: Sérgio Carvalho

I know MongoLink has to work with the behaviors inherit by MongoDB, but why not create a new function (e.g, named MongoCollectionFindType(coll, {query, typeexpect} )) in which the user say what kind of data it expects to find in the query and if some documents have different types of the expected the function does that conversion in order to make the comparison

Because its a deeply non-performant hack to the correct solution: storing the data in the correct format. And if users really insist on storing data with incorrect types, they are free to use MongoCollectionAggregate with the $convert op (https://docs.mongodb.com/manual/reference/operator/aggregation/convert/) if they have MongoDB +4.0 and are willing to pay the appropriate performance penalties.

POSTED BY: Sérgio Carvalho

is important not to miss this issues before the data gets stored and starts to grow.

Use MongoDB schema validation in this case to prevent invalid data from being inserted into the database: https://docs.mongodb.com/manual/core/schema-validation/

POSTED BY: Sérgio Carvalho

There is a good presentation with practical code examples about Mathematica with MongoDB here:

MongoDB with WL- .NB Presentation

POSTED BY: Daniel Carvalho

Here is a related SE post: mathematica.stackexchange.com/questions/40731

POSTED BY: Rodrigo Murta
Posted 11 years ago

Hello! Old thread, but I recently made my MongoDB Mathematica driver open-source here: https://github.com/zbjornson/MongoDBLink.

POSTED BY: Zach Bjornson
Hi Steeve,

I am not aware of a direct link between mathematica and MongoDB but could I recommend using JLink and then writting your mongo interface through Java?

Even though it is not a complete solution I know MongoDB does have a REST interface that you could interface through... however it has no support for insert/update/remove operations... But you could read your data at least and you can use Mathematica's ability to communicate through HTTP requests to read the data.

If you aren't completely locked into Mongo you could also look at couchdb (http://couchdb.apache.org/) which does have a fully formed REST API. It also takes an optimistic approach to data and instead of locking an entire local instance of the database to write data it versions data which also allows for ACID compliance as opposed to Mongo's partial ACID compliance. All of this being said CouchDB does seem to only allow you to query through map/reduce (and often you just have to write the map function. I am also still not clear on how their indexing works, but it appears to index through the map functions that are written.. I really need to do something with this data store to understand how it works better).

All in all I have used mongo before and love it. I have not used couchdb yet but it could be an alternative if you aren't willing/can't create a java interface for mongodb.

Adam Martinek
POSTED BY: Adam Martinek
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard