- Reference >
- Database Commands >
- Administration Commands >
- killCursors
killCursors¶
On this page
New in version 3.2.
Definition¶
-
killCursors¶ Kills the specified cursor or cursors for a collection. MongoDB drivers use the
killCursorscommand as part of the client-side cursor implementation.Note
In general, applications should not use the
killCursorscommand directly.The
killCursorscommand must be run against the database of the collection whose cursors you wish to kill.To run killCursors, use the
db.runCommand( { <command> } )method.The command has the following form:
Field Type Description killCursorsstring The name of the collection. cursorsarray The ids of the cursors to kill. commentany Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:
- mongod log messages, in the
attr.command.cursor.commentfield. - Database profiler output, in the
command.commentfield. currentOpoutput, in thecommand.commentfield.
A comment can be any valid BSON type (string, integer, object, array, etc).
New in version 4.4.
- mongod log messages, in the
Required Access¶
Kill Own Cursors¶
- In MongoDB 4.2 and later, users can always kill their own cursors,
regardless of whether the users have the privilege to
killCursors. Cursors are associated with the users at the time of cursor creation. - In MongoDB 3.6.3 through MongoDB 4.0.x, users require
killCursorsprivilege to kill their own cursors. Cursors are associated with the users at the time of cursor creation.
Kill Any Cursor¶
If a user possesses the killAnyCursor privilege, that
user may kill any cursor, even cursors created by other users.
killCursors and Transactions¶
Starting in MongoDB 4.2, you cannot specify killCursors as
the first operation in a transaction.
Example¶
Consider the following find operation on the
test.restaurants collection:
which returns the following:
To kill this cursor, use the killCursors command.
killCursors returns the following operation details: