> For the complete documentation index, see [llms.txt](https://docs.ondiagram.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ondiagram.com/nodes/mongodb.md).

# MongoDB

## General

The `MongoDB` node allows to create, read, update and delete objects on **any** instance of Mongo DB.

## Input

CASE: Insert / One

* **Data:** Receives an `Object` with the data to insert to the collection. Learn more on [mongodb.collection.insertOne](https://docs.mongodb.com/manual/reference/method/db.collection.insertOne/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.insertOne](https://docs.mongodb.com/manual/reference/method/db.collection.insertOne/).

CASE: Insert / Many

* **Data:** Receives an array of `Object` with the data to insert to the collection. Learn more on [mongodb.collection.insertMany](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.insertMany](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/).

CASE: Find / One

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.findOne](https://docs.mongodb.com/manual/reference/method/db.collection.findOne/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.findOne](https://docs.mongodb.com/manual/reference/method/db.collection.findOne/).

CASE: Find / Many

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.insertMany](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.insertMany](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/).

CASE: Update / One

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.updateOne](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/).
* **Data:** Receives an array of `Object` with the data to update to the collection. Learn more on [mongodb.collection.updateOne](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.updateOne](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/).

CASE: Update / One (Replace)

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.replaceOne](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/).
* **Data:** Receives an array of `Object` with the data to update to the collection. Learn more on [mongodb.collection.replaceOne](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.replaceOne](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/).

CASE: Update / Many

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.updateMany](https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/).
* **Data:** Receives an array of `Object` with the data to update to the collection. Learn more on [mongodb.collection.updateMany](https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.updateMany](https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/).

CASE: Delete / One

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.deleteOne](https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.deleteOne](https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/).

CASE: Delete / Many

* **Filter:** Receives an `Object` with the query selection criteria. Learn more on [mongodb.collection.deleteMany](https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/).
* **Options:** *(optional)* Receives an `Object` with options for the operation. Learn more on [mongodb.collection.deleteMany](https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/).

Environment variables:

* **mongodb:** Requires *Connection String* to be set.

## Output

\*\*\*\*

CASE: Insert / One

* **Out:** Returns an `Object` containing, a `Boolean` indicating write concern and a `String` insertedId with the \_id value of the inserted document. Learn more on [mongodb.collection.insertOne](https://docs.mongodb.com/manual/reference/method/db.collection.insertOne/).

CASE: Insert / Many

* **Out:** Returns an `Object` containing, a `Boolean` indicating write concern and a `String` insertedId with the \_id value of the inserted document. Learn more on [mongodb.collection.insertMany](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/).

CASE: Find / One

* **Out:** Returns an `Object` that satisfies the query criteria which contains a `String` with the \_id field. If you specify a projection parameter, it contains the projection fields. Learn more on [mongodb.collection.findOne](https://docs.mongodb.com/manual/reference/method/db.collection.findOne/).

CASE: Find / Many

* **Out:** Returns an array of `Object` that satisfies the query criteria which contains a `String` with the \_id field. If you specify a projection parameter, it contains the projection fields. Learn more on [mongodb.collection.findMany](https://docs.mongodb.com/manual/reference/method/db.collection.findMany/).

CASE: Update / One

* **Out:** Returns an `Object`, containing a `Number` with the number of matched documents, a `Number` with the number of modified documents, a `String` with the \_id of the inserted document and a `Boolean` indicating write concern. Learn more on [mongodb.collection.updateOne](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/).

CASE: Update / One (Replace)

* **Out:** Returns an `Object`, containing a `Number` with the number of matched documents, a `Number` with the number of modified documents, a `String` with the \_id of the inserted document and a `Boolean` indicating write concern. Learn more on [mongodb.collection.replaceOne](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/).

CASE: Update / Many

* **Out:** Returns an `Object`, containing a `Number` with the number of matched documents, a `Number` with the number of modified documents, a `String` with the \_id of the inserted document and a `Boolean` indicating write concern. Learn more on [mongodb.collection.updateMany](https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/).

CASE: Delete / One

* **Out:** Returns an `Object` containing, a `Boolean` indicating write concern and a `Number` with the number of deleted documents. Learn more on [mongodb.collection.deleteOne](https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/).

CASE: Delete / Many

* **Out:** Returns an `Object` containing, a `Boolean` indicating write concern and a `Number` with the number of deleted documents. Learn more on [mongodb.collection.deleteMany](https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/).

## Use Cases

Retrieve a document from the database.

* Request (Get) ➡ MongoDB (Get) ➡ Response (200)

Update a document from the database.

* Request (Post) ➡ MongoDB (Post) ➡ Response (200)
