← All procedures

mongo.documents.bulk

Several writes in one request: insertOne, updateOne, updateMany, deleteOne and deleteMany, in order by default

CLI
Package
@procedures/mongo · README
Path
["mongo","documents","bulk"]
CLI
mark mongo documents bulk --operations <object | object | object | object | object[]>
As data
{"$proc":["mongo","documents","bulk"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/mongo/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["mongo","documents","bulk"], { operations: [] });
console.log(JSON.stringify(result));

From the command line

$ mark mongo documents bulk --operations <object | object | object | object | object[]>

As data, in a program

{
  "$proc": ["mongo", "documents", "bulk"],
  "input": { "operations": [] }
}

Input

FieldTypeRequiredDefaultDescription
collectionstringnoThe collection name. It takes the place of metadata.collection.
databasestringnoThe database name (default: the database of the connection)
operationsobject | object | object | object | object[]yesThe writes, in order: each one is { insertOne }, { updateOne }, { updateMany }, { deleteOne } or { deleteMany }
orderedbooleannoTrue (the default): the first failure stops the rest. False: the server tries each write.
confirmbooleannoSet to true to use an empty filter, which matches every document, in an update or a delete

Output

FieldTypeRequiredDefaultDescription
okbooleanyesTrue when the server confirmed the writes
insertedCountnumberyesThe number of inserted documents
matchedCountnumberyesThe number of documents that the updates matched
modifiedCountnumberyesThe number of documents that the updates changed
deletedCountnumberyesThe number of deleted documents
upsertedCountnumberyesThe number of documents that an upsert made
insertedIdsobjectyesThe ids of the inserted documents, as text, by the index of their operation
upsertedIdsobjectyesThe ids of the upserted documents, as text, by the index of their operation
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "collection": {
        "description": "The collection name. It takes the place of metadata.collection.",
        "type": "string",
        "minLength": 1
      },
      "database": {
        "description": "The database name (default: the database of the connection)",
        "type": "string",
        "minLength": 1
      },
      "operations": {
        "minItems": 1,
        "type": "array",
        "items": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "insertOne": {
                  "type": "object",
                  "properties": {
                    "document": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "The new document"
                    }
                  },
                  "required": [
                    "document"
                  ]
                }
              },
              "required": [
                "insertOne"
              ]
            },
            {
              "type": "object",
              "properties": {
                "updateOne": {
                  "type": "object",
                  "properties": {
                    "filter": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "The filter of the documents. An empty filter needs confirm: true."
                    },
                    "update": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        }
                      ],
                      "description": "The update operations, for example { $set: { status: \"done\" } }, or a pipeline"
                    },
                    "upsert": {
                      "description": "Insert a document when none matches",
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "filter",
                    "update"
                  ]
                }
              },
              "required": [
                "updateOne"
              ]
            },
            {
              "type": "object",
              "properties": {
                "updateMany": {
                  "type": "object",
                  "properties": {
                    "filter": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "The filter of the documents. An empty filter needs confirm: true."
                    },
                    "update": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        }
                      ],
                      "description": "The update operations, for example { $set: { status: \"done\" } }, or a pipeline"
                    },
                    "upsert": {
                      "description": "Insert a document when none matches",
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "filter",
                    "update"
                  ]
                }
              },
              "required": [
                "updateMany"
              ]
            },
            {
              "type": "object",
              "properties": {
                "deleteOne": {
                  "type": "object",
                  "properties": {
                    "filter": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "The filter of the documents. An empty filter needs confirm: true."
                    }
                  },
                  "required": [
                    "filter"
                  ]
                }
              },
              "required": [
                "deleteOne"
              ]
            },
            {
              "type": "object",
              "properties": {
                "deleteMany": {
                  "type": "object",
                  "properties": {
                    "filter": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "The filter of the documents. An empty filter needs confirm: true."
                    }
                  },
                  "required": [
                    "filter"
                  ]
                }
              },
              "required": [
                "deleteMany"
              ]
            }
          ]
        },
        "description": "The writes, in order: each one is { insertOne }, { updateOne }, { updateMany }, { deleteOne } or { deleteMany }"
      },
      "ordered": {
        "description": "True (the default): the first failure stops the rest. False: the server tries each write.",
        "type": "boolean"
      },
      "confirm": {
        "description": "Set to true to use an empty filter, which matches every document, in an update or a delete",
        "type": "boolean"
      }
    },
    "required": [
      "operations"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "ok": {
        "type": "boolean",
        "description": "True when the server confirmed the writes"
      },
      "insertedCount": {
        "type": "number",
        "description": "The number of inserted documents"
      },
      "matchedCount": {
        "type": "number",
        "description": "The number of documents that the updates matched"
      },
      "modifiedCount": {
        "type": "number",
        "description": "The number of documents that the updates changed"
      },
      "deletedCount": {
        "type": "number",
        "description": "The number of deleted documents"
      },
      "upsertedCount": {
        "type": "number",
        "description": "The number of documents that an upsert made"
      },
      "insertedIds": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "string"
        },
        "description": "The ids of the inserted documents, as text, by the index of their operation"
      },
      "upsertedIds": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "string"
        },
        "description": "The ids of the upserted documents, as text, by the index of their operation"
      }
    },
    "required": [
      "ok",
      "insertedCount",
      "matchedCount",
      "modifiedCount",
      "deletedCount",
      "upsertedCount",
      "insertedIds",
      "upsertedIds"
    ],
    "additionalProperties": {}
  }
}