You can determine the status of a running query using $currentOp (aggregation). To run $currentOp, use the db.aggregate() helper.
Observação
If you are an Admin user, you can view all queries using the $currentOp allUsers option.
$currentOp must be run against the admin database.
Observação
If your aggregation pipeline only contains the $currentOp stage, Atlas Data Federation doesn't enforce the limit on the maximum number of simultaneous queries. You can run queries that only contain the $currentOp stage even after you reach the maximum number of simultaneous queries.
Sintaxe
db.aggregate([{$currentOp: {} }])
Saída
$currentOp retorna documentos com os seguintes campos:
Campo | Tipo | Descrição |
|---|---|---|
| string | Tipo de operação. O valor é sempre |
| Unique identifier of the operation in ObjectId format. The field value is the same as the | |
| string | Endereço IP (ou nome do host) e a porta efêmera da conexão do cliente onde a operação se origina. |
| Documento | Informações adicionais do cliente, como o cliente:
|
| booleano | Especifica se a operação foi iniciada. O valor é |
| Hora de início da operação. | |
| string | Namespace that the operation targets. A namespace consists of the database name and the collection name concatenated with a dot ( |
| Documento | Um documento contendo o objeto de comando associado a esta operação. |
| string | Uma mensagem que descreve o status e progresso da operação. |
| Documento | Um documento que contém a quantidade de trabalho feito para a operação. |
| inteiro | Um número que aumenta à medida que os documentos passam pelo pipeline, indicando que foi feito progresso em relação à conclusão da query. Esse número não é uma porcentagem e não pode ser usado para estimar quanto trabalho resta. |
Exemplos
No exemplo abaixo, suponha que uma das seguintes queries esteja sendo executada na collection airbnb no banco de dados sample descrita no tutorial de Introdução.
db.airbnb.find( { "address.market" : "Porto", "review_scores.review_scores_rating": {$gt: 79}}).comment("Find properties in Porto")
db.airbnb.aggregate( [ { $match: { "address.market": "Porto", "review_scores.review_scores_rating": {$gt: 79} } } ], { comment: "Find properties in Porto" })
O exemplo a seguir retorna informações sobre a query anterior em execução na collection airbnb no reconhecimento de data center sample :
db.aggregate([{$currentOp: {} }])
$currentOp returns the following documents. The workDone field shows that 770 documents had been processed at the time that $currentOp was run.
{ "type" : "op", "opid" : ObjectId("1635fa35bf73f4320c6f99d0"), "client" : "73.231.201.205:62351", "clientMetadata" : { "application" : { "name" : "MongoDB Shell" }, "driver" : { "name" : "MongoDB Internal Client", "version" : "4.2.0" }, "os" : { "type" : "Darwin", "name" : "Mac OS X", "architecture" : "x86_64", "version" : "18.7.0" } }, "active" : true, "currentOpTime" : ISODate("2020-03-26T12:51:43.291Z"), "ns" : "sample.airbnb", "command" : { "find" : "airbnb", "filter" : { "address.market" : "Porto", "review_scores.review_scores_rating" : { "$gt" : 79 } }, "comment" : "Find properties in Porto", "lsid" : { "id" : UUID("2211f8ac-56b2-4ba4-bb0c-2e5dd5b7cc21") }, "$db" : "sample" }, "msg" : "work done: 770", "progress" : { "workDone" : 770 } } { "type" : "op", "client" : "73.231.201.205:62353", "clientMetadata" : { "application" : { "name" : "MongoDB Shell" }, "driver" : { "name" : "MongoDB Internal Client", "version" : "4.2.0" }, "os" : { "type" : "Darwin", "name" : "Mac OS X", "architecture" : "x86_64", "version" : "18.7.0" } }, "active" : true, "currentOpTime" : ISODate("2020-03-26T12:51:47.380Z"), "ns" : "admin.$cmd.aggregate", "command" : { "aggregate" : 1, "pipeline" : [ { "$currentOp" : { } } ], "cursor" : { }, "lsid" : { "id" : UUID("045ea383-65d7-4e88-a989-37b7a8da23bc") }, "$db" : "admin" }, "msg" : "work done: 0", "progress" : { "workDone" : 0 } }