Simulate slow query in mongodb?

前端 未结 3 1721
野性不改
野性不改 2021-02-15 23:35

Does MongoDb have anything like MySql\'s SELECT SLEEP(5); ?

I can see some internal sleep function that would pause the whole server, but I need to pause ju

3条回答
  •  死守一世寂寞
    2021-02-16 00:32

    You can use the $where operator to call sleep(). This should work in any language or ORM/ODM. For example, in Mongoid you could do:

    Model.where( :$where => "sleep(100) || true" ).count
    

    Tune the sleep value for the number of documents in the collection (it will delay on each one). This will do fairly horrible things to the DB server, so only use it for testing, and never (ever!) on a production server.

提交回复
热议问题