MongoDB Connector 26.1
MongoDB Connector Help

# Insert Data into MongoDB

The connector's `insert` fetch action can insert collections and documents into MongoDB.

To use the `insert` action, you must construct some XML that specifies the information to insert.

- Insert a Collection
- Insert a Document

Add the XML to the insert fetch action as the value of the `insertXML` action parameter. The XML must be URL encoded before being used in the action command. For example:

    http://host:port/action=Fetch&FetchAction=Insert
                                 &ConfigSection=MyTask
                                 &InsertXML=[URL encoded XML]

For more information about using the `insert` fetch action, refer to the MongoDB Connector Reference.

## Insert a Collection

To insert a collection, set the following properties.

Name | Description
--- | ---
`Type` | The type of item to insert into MongoDB. Set this to "Collection".
`DatabaseName` | The name of the database to insert the collection into.
`CollectionName` | The name of the new collection.

For example, the following XML could be used to insert a new collection named "ExampleCollection" into a database named "ExampleDatabase".

    <insertXML>
        <insert>
            <reference>mongodb:ExampleDatabase/ExampleCollection</reference>
            <property name="Type" value="Collection"/>
            <property name="CollectionName" value=" ExampleCollection "/>
            <property name="DatabaseName" value=" ExampleDatabase "/>
        </insert>
    </insertXML>

## Insert a Document

To insert a document, set the following properties.

Name | Description
--- | ---
`Type` | The type of item to insert into MongoDB. Set this to "Document".
`DatabaseName` | The name of the database to insert the document into.
`CollectionName` | The name of the collection to insert the document into.

In your XML, you must also use the `file` element to specify the field values to insert. There are several ways that you can do this, for example specifying the path to a file or providing the content base-64 encoded. The file must be a JSON file containing the fields and field values. For more information about how to specify a source file, refer to the documentation for the `insert` action in the MongoDB Connector Reference.

The following example would insert a document into the collection named "ExampleCollection" in the database named "ExampleDatabase". The field values to insert are contained in the `<content>` element, base-64 encoded.

    <insertXML>
        <insert>
            <reference>mongodb:ExampleDatabase/ExampleCollection/DocumentID</reference>
            <property name="Type" value="Document"/>
            <property name="CollectionName" value=" ExampleCollection "/>
            <property name="DatabaseName" value=" ExampleDatabase "/>
            <file>
                <type>content</type>
                <content>BASE64FILE==</content>
            </file>
        </insert>
    </insertXML>

Copyright 2025 Open Text
Version 26.1 | Last updated January 2026

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: Knowledge Discovery MongoDB Connector 26.1

Topic Title: Insert Data into MongoDB