search

Home  >  Q&A  >  body text

mongodb有没有后端执行的操作可以立马得到回馈的?

比如redis哈。 你提交一个bgrewriteaof。会立马得到一个回复。即程序与redis的连接结束。redis自己在默默的执行操作。

mongodb有木有类似的命令参数?比如我remove掉一批object。尼玛等了30多分钟……= =。难道就木有 一个 db.collection.remove({param},{background:true})?= =

大家讲道理大家讲道理2768 days ago635

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-21 11:20:58

    See here: http://docs.mongodb.org/manual/reference/write-concern/

    MongoDB Default w=1。你可以传个 w=0 tells MongoDB that you don’t want to wait for its write operation to complete.

    reply
    0
  • PHPz

    PHPz2017-04-21 11:20:58

    This is called "asynchronous return". Some languages ​​(such as Java) have mongodb asynchronous drivers. You can gogogle mongodb async + the language you use.

    reply
    0
  • 黄舟

    黄舟2017-04-21 11:20:58

    Currently, redis is more inclined to use in-memory databases, but redis can configure a persistence strategy, which can persist the data in the memory to the hard disk and automatically restore it on the next restart. bgrewriteaof is just a command that allows administrators to manually trigger AOF rewriting when redis adopts the AOF persistence strategy. Starting from Redis 2.4, AOF rewriting is automatically triggered by Redis. The main thread of such a Redis server will write data into the memory and AOF every time it accepts an operation command, and then Redis will automatically fsync it to the hard disk, which will not cause blocking of user operations. See: Redis Persistence

    Mongodb is positioned as a Document based database and natively supports distributed architecture. As a document database, the guarantee of persistence is that all data must be written to the hard disk before the operation is successful. The distributed architecture brings more complex issues to persistence operations (ensuring data synchronization between multiple servers, distributed writing strategies, etc.).

    In summary, don’t expect a certain function provided by Redis. Mongodb also provides it, because the two have different focuses. Redis focuses more on high-performance I/O, while mongodb focuses more on the storage of large amounts of data. , while taking into account performance.

    Judging from your description, the operation requesting mongodb is severely blocked. It is recommended to combine your needs and attach WriteConcern when requesting mongodb operations to define the write operation strategy you can tolerate. See: WriteConcern

    reply
    0
  • Cancelreply