Introduction
In this blog post, you will learn how to call MongoDB Shell Commands from SSIS using MongoDB ExecuteSQL task
Some of the use cases of calling MongoDB shell commands are listed here.
How to call MongoDB Shell Commands in SSIS
- Download and install SSIS PowerPack from here
- From toolbox of SSIS designer drag ZS MongoDB ExecuteSQL Task
- Click on New Connection (Next to connection dropdown)
- Configure MongoDB connection and click Test. Close UI by clicking OK
- Now on the Task UI configure it as below. Notice “Examples” dropdown. that’s best way to learn various commands.
- You can also use “Insert Variables” option to make your command dynamic (Read value from SSIS variable)
Add MongoDB User
To Add MongoDB user using MongoDB ExecuteSQL Task use following Script
1 2 3 4 5 6 |
{ scope: 'database', command: 'eval', db: 'Northwind', args: { code: 'db.createUser( { user: "myUser1", pwd: "password123",roles: [ "readWrite", "dbAdmin" ] })' } } |
Remove MongoDB User
To Remove MongoDB user using MongoDB ExecuteSQL Task use following Script
1 2 3 4 5 6 |
{ scope: 'database', command: 'eval', db: 'Northwind', args: { code: 'db.removeUser("myUser1")' } } |
List MongoDB Users from Command Line
To list existing users for specific database perform following steps.
- Open command prompt and type mongo
- If needed type userid/password (if not needed then do next step)
- type use YourDBName
- Type db.getUsers()