Skip to main content
Skip table of contents

Inserting and Deleting Documents

You can use the MongoDB adapter to interact with a MongoDB and to insert, get and manipulate documents.

Inserting Documents

Using one of the insert operations, you can insert one or more documents into a MongoDB.

The MongoDB adapter comes with two insert operations: one to insert a single document, the other to insert multiple documents at once.

Name

Type

Description

document

<document class>

A single object of an xUML class representing the document structure.

documents

Array of <document class>

An array of objects of an xUML class representing the document structure.

Refer to the reference of the insert operations for a detailed description of all parameters and options.

Deleting Documents

Using the delete operation, you can remove one or more documents from a MongoDB.

For all actions that refer to existing documents, you need to provide a query string (queryString) to identify them. A query string contains all properties of the document you want to use for selection.

Assume we have the following sample Customer document structure:

CODE
{
  "id": "ebd7c78b-44e0-4cbd-8164-d28431716942"
            
  "name": "John Snow",
  "company": "Winter & Partners",
  "address": {
    "street": "99, Malamute Street",
    "city": "Anchorage, AK 99506",
    "country:": "USA"
  },
  orderValue: "16323.00
}

The simplest way to create a query string is the following:

  1. Create an object having the structure of the document ( Customer in the example).

    CODE
    create queryData;
  2. Set all query values to this object (the customerID in the example).

    CODE
    set queryData.id = customerID;
  3. Provide this object as queryString by converting it to JSON using classToExtendedJSON().

    CODE
    set queryString = queryData.classToExtendedJSON();

To build a query string, we recommend to not use concat() operations but to create a data structure that represents the update string and can be converted to JSON with classToExtendedJSON().

Building a query string manually (e.g. using concat()) is susceptible to code injection.

You can remove all documents from the collection by providing { } as queryString.

Refer to reference of the delete operations for a detailed description of all other parameters and options.

MongoDBAdapter_CustomerData_Example

Click here to download a simple example model that shows the usage of the MongoDB adapter in Scheer PAS Designer.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.