Is an ORM redundant with a NoSQL API?

北慕城南 提交于 2019-12-20 17:35:27

问题


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?


回答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.




回答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/




回答3:


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




回答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).




回答5:


depends upon how mature is driver provided with the NoSQL database. This link discusses relevance of ORM tools for NoSQL database: http://xamry.wordpress.com/2012/08/10/sqlifying-nosql-are-orm-tools-relevant-to-nosql/




回答6:


All you really need is a serializer/deserializer to make this work.

Norm has done a great job of doing just that. Makes it easier to take straight poco objects and just save them to mongo with a single line of code.

They call Norm an ORM, but its really just a poco to dictionary mongo wrapper.

An orm is just extra ceremony for these operations. If your data operations are abstracted into a repository, its going to be a non-issue either way, because converting to another backing store is an object per object, basis.



来源:https://stackoverflow.com/questions/2694044/is-an-orm-redundant-with-a-nosql-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!