Use MongoDB

What is MongoDB?

MongoDB is an open-source leading NoSQL database. A non-relational database is called a NoSQL database. Instead of using tables and rows as in relational databases, MongoDB is built on an architecture of collections and documents. The collections are an equivalent of RDBMS tables. A collection holds one or more documents, which corresponds to a record or a row in a relational database table, and each document has one or more fields, which corresponds to a column in a relational database table. MongoDB uses JSON documents in order to store records, just as tables and rows store records in a relational database. MongoDB represents JSON documents in binary-encoded format called BSON behind the scenes.

How to use MongoDB in Xalt | Integration?

Xalt | Integration's DBReader and DBWriter components can leverage the MongoDB database. You can now preform a variety of MongoDB create, read, update, and read (CRUD) operations from the DBReader and DBWriter components. Each instance of a DBReader or DBWriter component represents a single MongoDB database on a single server with multiple collections.

The MongoDB feature uses the Database Type NoSQL and the Connection Type MongoDB.

The Database Type NoSQL must be selected to view the dialog to enter Collection names.

Establishing a connection

Xalt | Integration currently follows MongoDB 3.4 standards for the connection string. Specify the connection string in the format shown below:

mongodb://[username:password@]host1[:port1][/[databaseName][?options]]

  • The default port for MongoDB is 27017.
  • MongoDB uses a connection pool to automatically manage connections between Xalt | Integration and the MongoDB database. Meaning that once Xalt | Integration establishes a connection to a MongoDB database, that connection is added to a pool, the connection pool will determine when to release that connection after a period of inactivity. This period can be customized in the [?options] of the connection sting. The default is 30 minutes.

Database and Collections

  • If a database or collection does not exist, Xalt | Integration will automatically create the database in the connection string and the collections listed in the data grid view once an Action is preformed against the connected database or collections.
  • Each database is required to have at least one collection.

Commands

Action Parameters

  • Commands are entered into to Action Parameters > Value Of:
  • Commands are entered in either BSON or JSON format
  • All commands end as BSON documents

The following table lists the commands for DBReader and DBWriter.

DBReader Commands

DBWriter Commands

  • MongoQueryCommand(Command)
  • MongoRunCommand(Command)

Keywords

  • Two keywords are used to differentiate between the listed collections and all collections in the database.
    • The keyword "Component_Collection” will run the command on all the collections listed in the Collection dialog box.

      Example: {insert: "Component_Collection", �

    • The keyword “Database_Collection” will run the command on all collections in the database.

DBReader

  • The DBReader has the ability to Connect, Disconnect and run a variety of query commands.
  • The query command uses dot notation to traverse through BSON elements.
  • When a query command requires a collection name, use the keywords "Component_Collection” or “Database_Collection” to inject the collections into the query command.
  • Results are returned as BSON Documents.

DBWriter

  • The DBWriter has the ability to Connect, Disconnect and run a variety of CRUD commands.
  • When using the MongoDBRunCommand, the command is either run against the list of collections defined by the user or all collections in the database.
  • Success results are returned as true or false.

Example commands

// Create
{insert: "Component_Collection", 
	documents: 
	[
		{
			"gender": "male",
			"name": 
				{
				 	"first": "reginald",
					"last": "sanders"
				},
			"location": 
				{
                        				"street": "1952 church lane",
                        				"city": "leeds",
                        				"state": "shropshire",
                        				"postcode": "G0 6BR"
                    			}
		}, 
            		{
			"gender": "female",
			"name": 
				{
                        				"first": "bobbie",
                        				"last": "perez"
				},
				"location": 
					{
						"street": "7902 mcgowen st",
						"city": "geelong",
						"state": "western australia",
						"postcode": 9250
					}
		}
	]
}

        
// Query 1
{find: "Component_Collection", 
    filter: {"name.first": "bobbie"	}
}

        
// Query 2
{ listCollections: 1}

        
}

        
// Update
{ update: "Database_Collection",
    updates: [
                { 
                    q: {"street": "7902 mcgowen st"}, 
                    u: { $set: { "street": "187 king st" }}, 
                    multi: true 
                }
             ]                                
}

        
// Delete
{delete: "Component_Collection", 
    deletes: [
                { 
                    q: {"name.first": " bobbie "}, 
                    limit: 0 
                }
             ]
}

SHARED Tip More commands can be found at https://docs.mongodb.com/manual/reference/command/.