Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda