Mongodb解惑(2011/05/06 ~ 2011/07/10)

下面是几个我在mongodb quora(2011/05/06 ~ 2011/07/10)上看到比较有意思的问题和答案:

How do I migrate data from mysql database to mongoDB?


A quick Google search brought up this: http://ananasblau.com/2010/2/1/mysql-to-mongodb-conversion
And I'm sure there are more, but I think that as your data is unique to you, you could quickly write a script to go through each record in your database and generate a json document out of it, including all the related data that goes with it. I don't think a 1:1 mapping of tables and collections will give you the benefit of a document database like mongoDb. Such a script should be pretty quick to write. I suspect a day's work once you know what you're trying to achieve.

Do take time to go through your data and analyze how you'd like the Json (Bson) documents to be structured. You'll obviously have to adjust your application code to deal with the new structures. 
Remember that you're after a certain level of de-normalization of data and don't try to mimic relational structure too much. Its counter productive in that context.


Is it possible to do realtime mapreduce in MongoDB incrementally on output collection for CRUD operations on the input collection?


Let's start with clarifying one thing, MongoDB's Map/Reduce is not intended for anything "real-time". Map/Reduce is a computationally expensive operation that will not produce real-time results.

Now it is possible to perform "incremental" Map/Reduce. Take a look at the "out" options:
http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Outputoptions

One of these options is the "reduce" another is "merge". These basically allow you to "increment" your map-reduce.

I'll demonstrate with an example. 

Let's say that you have daily stats that you want to update every hour. The simple way is to run a map-reduce on all of the data and update the entire results collection. Of course, as the day goes on your are re-processing a bunch of the same data.

The other way to do this is to process just the last hour's worth of data and use the "out": { "reduce" : collection }. This will apply the hour's worth of data to the existing data, so you only don't need to process data twice.

Based on your description, this seems to be what you're looking for. Please ask if you need further clarification.


In theory, yes. Map Reduce will yield during processing.

But each mongod process only has one instance of the javascript engine. The engine (currently spidermonkey) is not thread-safe, hence the limitation. So if you run two simultaneous Map/Reduce jobs, they are going to interrupt each other constantly. This will significantly impact performance.

Basically, you only get one core that will be able to run a Map / Reduce, regardless of how many jobs you throw at it. Additionally, Map / Reduce tends to fetch data that is not currently in memory. If you're doing this twice you can potentially tax your IO and that one core.

So the current recommendation is not to run multiple jobs.

That stated, 10gen has gone on record saying that aggregation and m/r performance are high on the features list for 1.9.x. With 1.9 already well underway, expect this answer to change over the coming weeks and months.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值