I would definitely second the recommendation of MongoMapper if you're going to be using MongoDB with Rails. I will warn you, however, that there is (so far) no documentation other than a couple blog posts. If you're not comfortable digging into the source code to see how things work, it's probably not for you yet.
If you're working outside of Rails, I'd recommend staying away from MongoMapper. Because it's working MongoDB into something similar to what we expect from a SQL-backed ORM, it doesn't really give you a good idea of the power of and of the different thinking behind MongoDB. Spend some time playing around with the lower-level ruby driver, and even in the javascript console.
The other thing I'd recommend, especially since you mentioned knowing how to normalize a schema, is not to think of MongoDB as a database for now. The way you organize your data in MongoDB is very different that with a relational database. Try to think about it more as a place to store and retrieve Ruby hashes. You can do some relational things with MongoDB, but I'd recommend sticking with only self-contained documents while you're trying to wrap your head around NoSQL.
As for what links you should look at, I'd highly recommend reading through everything you can on the MongoDB site. Their documentation is very good. Particularly, take a look at the advanced queries, multikey indexes, and MapReduce to get an idea of some of the unique advantages and strengths of a NoSQL database.
I am at nearly the same stage that you are. Starting a new project with MongoDB. I am around 7 weeks of experience. This is what I have found very useful:
The documentation is excellent. Seriously, excellent. It should take you about 15 min reading all the documentation and you will have a very exact idea of what you can do and cannot do with Mongoid.
Tomorrow, the release candidate for a new major version of mongoid will be released. It is going to brings a lot of useful things.
I am using Rails 3. To install the development version add this to your gem file:
gem 'mongoid', "~>2.0.0.beta"
Current beta is 20, but as I said, tomorrow there is the release candidate.
Also I sugest you to join the google group as well. It has low traffic and people are very willing to answer any question. For example I showed them my first DB Model design and they gave me many ways to improve that. The creator of Mongoid answer your questions too.
In two words: Great community.
There is this plugin that enables you to use Machinist with mongo:
Another thing I want to say. I come from a relation database world, so this sounded really weird to at the beginning: You can save files in a mongo database.
In fact, it could be faster than managing them as we used to do. This is because of mongo's support for sharding. Sharding means that you can use a cluster of computers to serve the Mongo Database. It is seamless. Master-slave. So you can serve a file from many computers, each sending a portion. It scales very well :)
$p->findOne(array('_id' => new MongoId( $UID )), array('proj'));
Show _id:
$coll['_id'] = ( string ) $coll['_id'];
Also _id is only unique per collection, can be different on other server
4. MongoDB has support for LIMIT,OFFSET,ORDER
for some advance sorting you can use Aggregation Framework.
5. In SQL is Sql injection in MongoDB is Array injection
So when write some data use ( string ) or check is_array
$req = (string) $range['name'];
6. HDD DOS
default _POST size is 8MB in PHP, IN Mongo there are limit per document 16MB. So imagine Some user spoof eq USER_AGENT STRING in you analytic script and then send 16MB per single insert.
7. There was some problems in past with MongoDb but right now 3.0 is pretty awesome and stable.
Mike Dirolf is intereviewed... he works on the MongoDb project. Oh, and the sound quality is excellent.
Mike Dirolf is a Software Engineer at 10gen, where he works on the MongoDB project. He mainly works on client drivers for Python and Ruby, but also takes time out to talk about MongoDB - he has presented at EuroPython, Strange Loop Conf, RubyEnRails, RuPy and RubyConf as well as at meetup groups in New York City, London, Washington D.C. and San Francisco.
You should definitively take a look into junemakers mongo-mapper: http://github.com/jnunemaker/mongomapper But I also recommend you to play a little bit with the pure Ruby Mongo driver to see how mongo-mapper works under the hood. It isn't very hard to put some data into a Mongo database using Ruby.
发布评论
评论(5)
如果您打算将 MongoDB 与 Rails 结合使用,我肯定会支持 MongoMapper 的推荐。但是,我要警告您,(到目前为止)除了几篇博客文章之外没有任何文档。如果您不愿意深入研究源代码来了解其工作原理,那么它可能不适合您。
如果您在 Rails 之外工作,我建议远离 MongoMapper。因为它将 MongoDB 处理成类似于我们对 SQL 支持的 ORM 的期望,所以它并没有真正让您很好地了解 MongoDB 背后的不同思维的力量。花一些时间尝试一下较低级别的 ruby 驱动程序,甚至在 javascript 控制台中。
我建议的另一件事是,现在不要将 MongoDB 视为数据库,特别是因为您提到了解如何标准化模式。在 MongoDB 中组织数据的方式与关系数据库中的数据非常不同。尝试将其更多地视为存储和检索 Ruby 哈希值的地方。您可以使用 MongoDB 做一些关系性的事情,但我建议您在尝试使用 NoSQL 时只使用独立的文档。
至于您应该查看哪些链接,我强烈建议您仔细阅读 MongoDB 网站上的所有内容。他们的文档非常好。特别是,请查看高级查询、多键索引,以及 MapReduce 了解 NoSQL 数据库的一些独特优势和优势。
I would definitely second the recommendation of MongoMapper if you're going to be using MongoDB with Rails. I will warn you, however, that there is (so far) no documentation other than a couple blog posts. If you're not comfortable digging into the source code to see how things work, it's probably not for you yet.
If you're working outside of Rails, I'd recommend staying away from MongoMapper. Because it's working MongoDB into something similar to what we expect from a SQL-backed ORM, it doesn't really give you a good idea of the power of and of the different thinking behind MongoDB. Spend some time playing around with the lower-level ruby driver, and even in the javascript console.
The other thing I'd recommend, especially since you mentioned knowing how to normalize a schema, is not to think of MongoDB as a database for now. The way you organize your data in MongoDB is very different that with a relational database. Try to think about it more as a place to store and retrieve Ruby hashes. You can do some relational things with MongoDB, but I'd recommend sticking with only self-contained documents while you're trying to wrap your head around NoSQL.
As for what links you should look at, I'd highly recommend reading through everything you can on the MongoDB site. Their documentation is very good. Particularly, take a look at the advanced queries, multikey indexes, and MapReduce to get an idea of some of the unique advantages and strengths of a NoSQL database.
我和你几乎处于同一阶段。使用 MongoDB 启动一个新项目。我大约有 7 周的经验。这是我发现非常有用的:
使用 Mongoid 而不是 Mongomapper
http://mongoid.org/< /a>
文档非常好。说真的,非常好。阅读所有文档大约需要 15 分钟,您将非常准确地了解 Mongoid 可以做什么和不能做什么。
明天,将发布新的 mongoid 主要版本的候选版本。它将带来很多有用的东西。
我正在使用 Rails 3。要安装开发版本,请将此添加到您的 gem 文件中:
gem 'mongoid', "~>2.0.0.beta"
当前 beta 是 20,但正如我所说,明天会有候选版本。
另外我建议你也加入谷歌小组。它的流量很少,人们很愿意回答任何问题。例如,我向他们展示了我的第一个数据库模型设计,他们给了我很多改进的方法。 Mongoid 的创建者也回答了你的问题。
简而言之:伟大的社区。
有一个插件可以让您将 Machinist 与 mongo 一起使用:
https://github.com/nmerouze/machinist_mongo
效果很好。
您可以使用 Machinist 进行伪造。很棒的组合。
https://github.com/sevenwire/forgery
我想说的另一件事。我来自关系数据库世界,所以一开始这听起来很奇怪:您可以将文件保存在 mongo 数据库中。
事实上,它可能比我们过去管理它们更快。这是因为 mongo 支持分片。分片意味着您可以使用计算机集群来为 Mongo 数据库提供服务。这是无缝的。主从。因此,您可以从多台计算机提供文件,每台计算机发送一部分。它的扩展性非常好:)
这是使用 GridFS 完成的。 http://www.mongodb.org/display/DOCS/GridFS
Mongoid 支持该 master -从机配置。
问我是否需要更多信息。
编辑:
另外:http://railscasts.com/episodes/238-mongoid
I am at nearly the same stage that you are. Starting a new project with MongoDB. I am around 7 weeks of experience. This is what I have found very useful:
Use Mongoid instead of Mongomapper
http://mongoid.org/
The documentation is excellent. Seriously, excellent. It should take you about 15 min reading all the documentation and you will have a very exact idea of what you can do and cannot do with Mongoid.
Tomorrow, the release candidate for a new major version of mongoid will be released. It is going to brings a lot of useful things.
I am using Rails 3. To install the development version add this to your gem file:
gem 'mongoid', "~>2.0.0.beta"
Current beta is 20, but as I said, tomorrow there is the release candidate.
Also I sugest you to join the google group as well. It has low traffic and people are very willing to answer any question. For example I showed them my first DB Model design and they gave me many ways to improve that. The creator of Mongoid answer your questions too.
In two words: Great community.
There is this plugin that enables you to use Machinist with mongo:
https://github.com/nmerouze/machinist_mongo
Works pretty well.
You can use Forgery with Machinist. Awesome mix.
https://github.com/sevenwire/forgery
Another thing I want to say. I come from a relation database world, so this sounded really weird to at the beginning: You can save files in a mongo database.
In fact, it could be faster than managing them as we used to do. This is because of mongo's support for sharding. Sharding means that you can use a cluster of computers to serve the Mongo Database. It is seamless. Master-slave. So you can serve a file from many computers, each sending a portion. It scales very well :)
This is done using GridFS. http://www.mongodb.org/display/DOCS/GridFS
Mongoid supports that master-slave config.
Ask me if you need more information.
Edit:
Also: http://railscasts.com/episodes/238-mongoid
1. 查询其不区分大小写的
eq
2. 最后插入 ID:
3. _id 是一个 MongoId 对象
通过 id 查找:
显示 _id:
另外 _id 仅在每个集合中是唯一的,在其他服务器上可以不同
4. MongoDB 支持 LIMIT ,OFFSET,ORDER
对于一些高级排序,您可以使用聚合框架。
5.在SQL中是Sql注入,在MongoDB中是数组注入
所以当写入一些数据时使用(字符串)或检查is_array
6.HDD DOS
默认_POST大小在PHP中是8MB,IN Mongo有每个文档16MB的限制。因此,想象一下某些用户在分析脚本中欺骗 eq USER_AGENT STRING,然后每次插入发送 16MB。
7. 过去 MongoDb 存在一些问题,但现在 3.0 非常棒且稳定。
1. Query its not case-sensitive
eq
2. Last insert ID:
3. _id is a MongoId object
Find by id:
Show _id:
Also _id is only unique per collection, can be different on other server
4. MongoDB has support for LIMIT,OFFSET,ORDER
for some advance sorting you can use Aggregation Framework.
5. In SQL is Sql injection in MongoDB is Array injection
So when write some data use ( string ) or check is_array
6. HDD DOS
default _POST size is 8MB in PHP, IN Mongo there are limit per document 16MB. So imagine Some user spoof eq USER_AGENT STRING in you analytic script and then send 16MB per single insert.
7. There was some problems in past with MongoDb but right now 3.0 is pretty awesome and stable.
这是来自 .NET Rocks 的一个很棒的初学者/MongoDb 播客介绍 -
http://www .dotnetrocks.com/default.aspx?ShowNum=507
Mike Dirolf 接受采访...他从事 MongoDb 项目。哦,音质非常好。
Here is a great beginner/introduction to MongoDb podcast from .NET Rocks -
http://www.dotnetrocks.com/default.aspx?ShowNum=507
Mike Dirolf is intereviewed... he works on the MongoDb project. Oh, and the sound quality is excellent.
你绝对应该看看 junemakers mongo-mapper: http://github.com/jnunemaker/mongomapper 但我也建议您尝试一下纯 Ruby Mongo 驱动程序,看看 mongo-mapper 在底层是如何工作的。使用 Ruby 将一些数据放入 Mongo 数据库并不难。
我想您已经找到了 Ruby Mongo 教程。以防万一您没有,这里是链接: http://www.mongodb .org/display/DOCS/Ruby+Tutorial
You should definitively take a look into junemakers mongo-mapper: http://github.com/jnunemaker/mongomapper But I also recommend you to play a little bit with the pure Ruby Mongo driver to see how mongo-mapper works under the hood. It isn't very hard to put some data into a Mongo database using Ruby.
I guess you already found the Ruby Mongo Tutorial. Just in case you didn't, here is the link: http://www.mongodb.org/display/DOCS/Ruby+Tutorial