在mongodb中模拟慢查询? [英] Simulate slow query in mongodb?

查看:341
本文介绍了在mongodb中模拟慢查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MongoDb是否具有MySql的SELECT SLEEP(5);之类的东西?

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 just the current query.

免责声明:仅用于测试目的

Disclaimer: just for testing purposes

推荐答案

您可以使用 $ where运算符调用sleep().这应该以任何语言或ORM/ODM运行.例如,在Mongoid中,您可以执行以下操作:

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.

这篇关于在mongodb中模拟慢查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆