Does MongoDB MapReduce lock the database

后端 未结 3 807
情书的邮戳
情书的邮戳 2021-02-14 09:50

Does a MongoDB MapReduce job lock the database? I am developing a multi-user MongoDB web application and am worried about multi-user conflicts and performance. Does anyone hav

相关标签:
3条回答
  • In version 2.1.0 added a "nonAtomic" flag to output option.

    See: https://jira.mongodb.org/browse/SERVER-2581

    0 讨论(0)
  • 2021-02-14 10:29

    No, mapreduce does not lock the database. See the note here, just after "Using db.eval()" (it explains why mapreduce may be more appropriate to use than eval, because mapreduce does not block).

    If you are going to run a lot of mapreduce jobs you should use sharding, because that way the job can run in parallel on all the shards. Unfortunately mapreduce jobs can't run on secondaries in a replica set, since the results must be written and replicas are read-only.

    0 讨论(0)
  • 2021-02-14 10:33

    Simple answer? Sometimes ...

    It depends a lot on how you are using map/reduce ... but in my experience it's never been a problem.

    There isn't much info on this, but it's clearly stated in the docs that is does sometimes lock but it "Allows substantial concurrent operation."

    There are a couple of questions in the mongodb-user group asking about this ... the best response I've seen offically is that ... "in 1.4 it yields but isn't as nice as it should be, in 1.5 its much friendlier to other requests."

    That does not mean that it doesn't block at all, but compared to db.eval() which blocks the whole mongod process ... it's your best bet.

    That said, in 1.7.2 and up there is now a nolock option for db.eval() ...

    0 讨论(0)
提交回复
热议问题