Is an ORM redundant with a NoSQL API?

17,306

Solution 1

Well, yes, Object-Relational mappers are redundant with MongoDB because MongoDB isn't a relational database, it's a Document-Oriented database.

So instead of SQL, you write queries in JSON. Unless you really, really want to write raw JSON, as opposed to, say, Linq, then you're still going to want to use a mapper. And if you don't want to create coupling against MongoDB itself, then you don't want to pass actual Document objects around, you want to map them to real POCOs.

The mapping is much easier with a document-oriented DB like MongoDB, because you have nested documents instead of relations, but that doesn't mean it goes away completely. It just means you've substituted one type of "impedance mismatch" for a different, slightly-less-dramatic mismatch.

Solution 2

I think an "ORM" on MongoDb can be useful, not only for "serializing" and "deserializing" objects into the db (Norm seems to do a great job) but also for making it more easy to execute aggregation queries.

It is nice if an "ORM" can generate MapReduce jobs for grouping and detecting duplicates. Some people have written code to automatically convert an sql statement into a mapreduce job: http://rickosborne.org/blog/index.php/2010/02/19/yes-virginia-thats-automated-sql-to-mongodb-mapreduce/

Solution 3

Take a look on Kundera : https://github.com/impetus-opensource/Kundera, ORM over mongodb, cassandra, HBase.

Solution 4

Another solution is PlayOrm which can do joins as well when necessary with it's Scalable-SQL language(just adds a prefix to normal SQL basically to add partition info).

Share:
17,306
Earlz
Author by

Earlz

Hello there! My name's Jordan Earls, but most people online know me as "earlz". I'm the lead developer and a co-founder of the Qtum project which brings the Ethereum Virtual Machine (ie, the thing that makes Solidity contracts function) to a UTXO based blockchain similar to Bitcoin. I've been programming since I was 13 and am completely self-taught. Low-level code like assembly and pointer arithmetic is the fun stuff for me. I also make music when I have time even though it's usually awful. Most of my personal projects are open source and BSD licensed. The majority of them are at bitbucket with the rest of them being listed on github Also, you can follow me on the twitters @earlzdotnet

Updated on June 11, 2022

Comments

  • Earlz
    Earlz almost 2 years

    with MongoDB (and I assume other NoSQL database APIs worth their salt) the ways of querying the database are much more simplistic than SQL. There is no tedious SQL queries to generate and such. For instance take this from mongodb-csharp:

    using MongoDB.Driver; 
    Mongo db = new Mongo(); 
    db.Connect(); //Connect to localhost on the default port. 
    Document query = new Document(); 
    query["field1"] = 10; 
    Document result = db["tests"]["reads"].FindOne(query); 
    db.Disconnect();
    

    How could an ORM even simplify that? Is an ORM or other "database abstraction device" required on top of a decent NoSQL API?

  • Aaronaught
    Aaronaught about 14 years
    Who calls NoRM an ORM? I thought it was a recursive acronym for " Not an Object Relational Mapper." Or maybe it's just "Not a Relational Mapper", since the "o" is lowercase. Either way, it's definitely not an ORM!
  • Aaronaught
    Aaronaught over 12 years
    @Cocowalla: I think NoRM is the only one that's really worth the bother at the moment. That may change in a year or two.
  • Marchy
    Marchy about 10 years
    Your answer dodges the problem that the question asks about - which is to understand the need for a higher-level abstraction that an ORM provides. Just like RDBMS's, document-oriented databases need to store relations between entities. As stated in the MongoDB intro docs (docs.mongodb.org/manual/core/data-modeling-introduction), you need to choose between embedding related data or referencing other documents. Related documents need subsequent queries, similar to lazy loading in Entity Framework. An ORM would be helpful in simplifying this, just as EF simplifies SQL joins.
  • Aaronaught
    Aaronaught about 10 years
    @Marchy: I wasn't "dodging" anything, and I don't agree that abstracting this away in MongoDB would be a good idea, as it would encourage developers to model data in a relational fashion when proper data modeling is the most crucial concern - as the very page you linked to clearly points out. Loading related documents one-by-one can kill performance, when most such databases have first-class support for minimizing round trips. Some, like RavenDB, even support query batching and relation-loading, which makes automatic lazy loading an even worse idea. I would not want to see that kind of "ORM".
  • geoidesic
    geoidesic over 8 years
    @Aaronaught Using an ORM is never optimally efficient, not even for SQL. That's not the point of an ORM. The point is to make it easy to deal with data (and security) via objects. If you want optimal, you always have to write native queries unless you're doing something incredibly simple.