Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
Pymongo: setting w for collection update overrides default write concern options

I have a pymongo collection and its write concern options are following:

>>> col1.__class__.__bases__
(<class 'pymongo.collection.Collection'>,)
>>> col1.write_concern
{'wtimeout': 6000}

I'm trying to insert a document in a replica set with only master available (slaves are blocked)

>>> pymongo.collection.Collection.update(col1, {'_id': '11'}, { "_id" : "11", "key": "test" }, upsert=True, fsync=False, w=2)

And pymongo hangs forever. Seems like setting w=2 explicitly overrides default wtimeout value to 0. If I send wtimeout=6000 to update it will throw an exception as expected. Am I missing something, or is it supposed to work this way?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's true that if you pass any write concern options to "update", they replace all the default write concern options. I don't think we've documented that.

Regardless, "update" is deprecated in favor of the much clearer update_one and update_many methods:

>>> from pymongo import WriteConcern
>>> collection = MongoClient().db.collection
>>> coll2 = collection.with_options(
...     write_concern=WriteConcern(w=2, wtimeout=6000))
>>> oid = coll2.replace_one({'_id': '11'}, { "_id" : "11", "key": "test" },
                            upsert=True)

See the PyMongo 3 guide:

http://api.mongodb.com/python/current/migrate-to-pymongo3.html#the-write-concern-attribute-is-immutable

Also, I'd recommend you use Python objects in the typical way, as in my example: instantiate an object and call a method on the instance, instead of calling a method on a class and passing an instance as "self".

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda