1

I'm trying to run the following in Python (with pymongo), however I always get the error message:

CursorNotFound: Cursor not found, cursor id: 16172789264

The code that I have (I tried to set "batch_size", but the error message continued):

import pymongo

client = pymongo.MongoClient()
db = client['tese']
carteiras_cvm = db['carteiras_cvm']

pipeline_acoes =[{"$unwind":"$posicao"},
           {"$match" : {"posicao.detalhes.Tipo de Aplicação:" : { "$in" : ['Ações','Brazilian Depository Receipt - BDR',
           'Ações e outros TVM cedidos em empréstimo','AÇÕES RECEBIDAS EM BONIFICAÇÃO']}}},
           {"$project":{"cnpj_fundo":"$cnpj_fundo", "data_carteira":"$data_carteira", "tipo_aplicacao":"$posicao.detalhes.Tipo de Aplicação:","cod_ativo":"$posicao.detalhes.Cod Ativo:","cod_isin":"$posicao.detalhes.Cod ISIN:","cod_isin":"$posicao.detalhes.Cod ISIN:","descricao":"$posicao.detalhes.Descrição:","posicao_final":"$posicao.posicao_final","perc_carteira":"$posicao.perc_carteira","pl_fundo":"$pl_posicao"}}]


def aggregate(db, pipeline):
    return [doc for doc in carteiras_cvm.aggregate(pipeline).batch_size(5)]

resultados_acoes = aggregate(carteiras_cvm, pipeline_acoes)

Any thoughts?

Stennie
  • 63,885
  • 14
  • 149
  • 175
fmarques
  • 391
  • 2
  • 5
  • 16

2 Answers2

1

Try add "no_cursor_timeout=True" in your cursor.

[doc for doc in carteiras_cvm.aggregate(pipeline,no_cursor_timeout=True).batch_size(5)]

Do tell me if this worked for you.

if the above code doesn't work try this link..

Is it possible to create an aggregation in Pymongo with no timeout for the cursor?

Yayati Sule
  • 1,601
  • 13
  • 25
1

no_cursor_timeout is not valid for method aggregate() in pymongo. You can use maxTimeMS instead.

maxTimeMS (int): The maximum amount of time to allow the operation to run in milliseconds.

timiTao
  • 1,417
  • 3
  • 20
  • 34