Tip
MongoDB también proporciona el método db.collection.bulkWrite() para realizar operaciones de guardar masiva.
Descripción
Bulk.find.replaceOne(<document>)Adds a single document replacement operation to a bulk operations list. Use the
Bulk.find()method to specify the condition that determines which document to replace. TheBulk.find.replaceOne()method limits the replacement to a single document.Bulk.find.replaceOne()acepta el siguiente parámetro:ParameterTipoDescripciónreplacementDocumento
Un documento de sustitución que reemplaza por completo el documento existente. Contiene solo pares de campo y valor.
La suma del documento
<query>asociado delBulk.find()y el documento de reemplazo debe ser menor o igual al tamaño máximo del documento BSON.Para especificar una inserción para esta operación, consulta
Bulk.find.upsert().Para especificar el índice a utilizar para el
Bulk.find()asociado, veaBulk.find.hint().
Compatibilidad
Este comando está disponible en implementaciones alojadas en los siguientes entornos:
- MongoDB Atlas: El servicio totalmente gestionado para implementaciones de MongoDB en la nube
Nota
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
Ejemplo
The following example initializes a Bulk() operations builder for the items collection, and adds various replaceOne() operations to the list of operations.
var bulk = db.items.initializeUnorderedBulkOp(); bulk.find( { item: "abc123" } ).replaceOne( { item: "abc123", status: "P", points: 100 } ); bulk.execute();