MongoDBWrite

MongoDBWrite performs write operations on a Mongo database.

Mongo is a NoSql database, which provides a mechanism for storage and retrieval of data that is different to the tabular relations used in relational databases like SQL Server, MySql and Oracle.

Properties

Collection

The collection to write to.

Connection string

A connection string to your database.

Operation

The operation to perform.

  1. Insert
    Inserts a single object (specified in the data property) into the database.
  2. Update
    Applies an update operation to any documents in the database that matches the criteria property.
  3. Replace
    Replaces a single document in the database with the object in the data property. The document to be replaced can either be specified by the criteria property, or by the ID attribute of the replacement document.
  4. Delete
    Deletes one or more documents in the database which match the criteria property
  5. Delete All
    Deletes all records in the collection.

Data

The object to be written into the database. The object can be specified either as a JSON formatted string, or as an instance of a custom type.

Required for insert, update, and replace operations.

Criteria

A MongoDb query document that specifies the selection criteria to be matched by a document in order for it to have the write operation applied.

For example, if we select from collection of documents with attributes "quantity" and "price", the criteria:

{ 
    $or: [
            { quantity: { $gt: 100 } },
            { price: { $lt: 9.95 } }
        ]
}

will match all documents in the collection with fields "quantity" greater than 100 or "price" less than 9.95.

Required for update, replace and delete operations.

An editor is provided to add database fields and variables to the criteria.

Insert If Not Found

Controls the action of replace and update operations, when no documents are found matching the criteria property.

  1. Checked
    A new document will be created.
  2. Unchecked
    No action will be taken.

Update Operation

A JSON formatted object containing one or more update operators specifying operations to be performed on the matched documents. For example:

{
    $set: { updated: true },
    $inc: { count: 1 }
}

will set an "updated" field to "true' and increment a "count" field for all matched documents.

An editor is provided to add database fields and variables to the update operation.

ID Attributes

Each document in a MongoDb collection is uniquely identified by an Object ID field called "_id". This field is automatically created whenever a new document is inserted into the database, and cannot be changed by update or replace operations.

When using the object id as an element in the criteria field, the string value will need to be converted back to a Mongo object id. For example, a document with id "525bc19331eec126ecdcf199" can be matched by using the criteria:

{ _id: ObjectId("525bc19331eec126ecdcf199") }

When running a replace operation without specifying any criteria, the function will attempt to replace a document in the database whose id matches a string field named "id" or "_id" in the replacement object. This allows objects to be read from the database using the MongoDBRead function, altered and written back to the database without requiring a replacement criteria.