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
or slow queries and operations. By default, mongod records slow queries to its log, as defined by slowOpThresholdMs. Enabling database profiler puts negative impact on MongoDB's performance.
We also call it “slow queries”. The slow queries can happen when you do not have proper DB indexes. Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement.
Performance. Because the index contains all fields required by the query, MongoDB can both match the query conditions and return the results using only the index. Querying only the index can be much faster than querying documents outside of the index.
One can identify slow queries in MongoDB by enabling the profiler and configuring it to its some specifications or executing db. currentOp() on a running mongod instance. By looking at the time parameters on the returned result, we can identify which queries are lagging.
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.
You can use the $where
operator as code_monkey_steve says, but be sure you do with mongo version >= 2.4. Before that version no javascript can be run on parallel on the same server. The sleep
command is javascript, so it would apparently block other javascript queries you could be making.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With