Examples
DB [Drop]: Drop database
This example shows how to drop MongoDB database (if database not found then error is raised).
{
scope: 'database',
db: 'YourDatabaseName',
command: 'drop'
}
DB [DropSafe]: Drop database if exists
This example shows how to drop MongoDB database if exists (if database not found then task succeed).
{
scope: 'database',
db: 'YourDatabaseName',
command: 'dropSafe'
}
DB [GetCollectionNames]: Get collection names
This example shows how to get collection names.
{
scope: 'database',
db: 'YourDatabaseName',
command: 'getCollectionNames'
}
DB [GetStats]: Get database statistics
This example shows how to fetch database statistics.
{
scope: 'database',
db: 'YourDatabaseName',
command: 'getStats'
}
DB [Eval]: Evaluate JavaScript
This example shows how to execute simple or complex multiline JavaScript code at server side.
{
scope: 'database',
command: 'eval',
args:
{
code: 'function()
{
var varCountry="USA";
return db.Customers.find({Country: varCountry }).limit(2).toArray()
}'
}
}
DB [Eval]: Using custom JSONPath Filter expression
This example shows how to execute any custom function or query and supply JSONPath expression to extract data from JSON Output. To test below you should set ResultType=FullResultset and click Test
{
scope: 'database',
command: 'eval',
filter: '$.result[*].price',
args:
{
code: 'function()
{
return db.MongodbSSISTest.find().toArray()
}'
}
}
DB [Eval]: Call function
This example shows how to call simple inbuilt or user defined function. If its user defined function then it must be created before you call in system.js collection (Read more about creating function in mongodb)
{
scope: 'database',
command: 'eval',
args: { code: 'db.hostInfo()' }
}
Collection [Create]: Create new collection
This example shows how to create new MongoDB collection (e.g. Table). If collection is already found then error is raised.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourNewCollectionName',
command: 'create'
}
Collection [CreateSafe]: Create new collection if not found
This example shows how to create new MongoDB collection if not found. If collection already exists then command is ignored.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourNewCollectionName',
command: 'createSafe'
}
Collection [Drop]: Drop collection
This example shows how to drop MongoDB collection (e.g. Table). If collection is not found then error is raised.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourCollectionName',
command: 'drop'
}
Collection [DropSafe]: Drop collection if exits
This example shows how to drop MongoDB collection if exists. If collection does not exist then command is ignored.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourCollectionName',
command: 'dropSafe'
}
Collection [Count]: Count records
This example shows how to count total records for specific MongoDB collection.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourCollectionName',
command: 'count'
}
Collection [Count]: Count records with condition
This example shows how to count total records with certain condition(s) for specific MongoDB collection.
{
scope: 'table',
db: 'YourDatabaseName',
table: 'YourCollectionName',
command: 'count',
args: {
query: { $or : [{country:'USA'},{country:'UK'}] }
}
}
Collection [Insert]: Insert document
This example shows how to insert new document into specific MongoDB collection.
{
scope: 'table',
table: 'YourCollectionName',
command: 'insert',
args:
{
doc:
{
_id : 1,
CustomerID : 'ALFKI',
CompanyName : 'Company 1',
RegistrationDate : ISODate('2001-01-01T00:00:00'),
ContactName : 'Maria1 Anders',
'Contact Title' : 'Sales Representative',
AddressInfo : { Address1: 'Obere Str. 57',City: 'Newyork',State: 'NY' } ,
Tags : ['aa','bb','cc']
}
}
}
Collection [Insert]: Insert multiple documents
This example shows how to insert multiple documents into MongoDB collection. This technique can be used to call any MongoDB Shell command
{
scope : 'database',
db : 'MyDB',
command : 'eval',
args : {
code : 'db.MyCollection.insert( [ {row:1,name:"AA"}, {row:2,name:"BB"} ] )'
}
}
Collection [Update]: Update existing document
This example shows how to update document/property of document (e.g. Update AdressInfo of customer document).
{
scope: 'table',
table: 'YourCollectionName',
command: 'update',
args:
{
doc:
{
AddressInfo : { Address1: 'Obere Str. 58',City: 'Redmond',State: 'WA' }
},
query: {_id : 1}
}
}
Collection [Update]: Use of update modifier (Insert to array using $push)
This example shows how to use update modifiers. For example use of $push modifier will insert new value to array inside your existing document. For more information about update modifiers check https://docs.mongodb.org/manual/reference/operator/update/ and to learn more about array modifier check https://docs.mongodb.org/manual/reference/operator/update-array/
{
scope: 'table',
table: 'YourCollectionName',
command: 'update',
args:
{
/*Check this link for more info on $push operator https://docs.mongodb.org/manual/reference/operator/update/push/ */
doc: { $push: { Tags: 'dd' } },
query: {RecID : 1}
}
}
Collection [Upsert]: Modify existing document with Upsert
This example shows how to If upsert is true and no document matches the query criteria, update() inserts a single document. The update creates the new document with either:
•The fields and values of the {update} parameter if the {update} parameter contains only field and value pairs, or
•The fields and values of both the {query} and {update} parameters if the {update} parameter contains update operator expressions. The update creates a base document from the equality clauses in the {query} parameter, and then applies the update expressions from the {update} parameter.
If upsert is true and there are documents that match the query criteria, update() performs an update.
{
scope: 'table',
table: 'YourCollectionName',
command: 'upsert',
args:
{
doc:
{
AddressInfo : { Country:'USA' }
},
query: {_id : 1}
}
}
Collection [Save]: Save document (Upsert by _id)
If the document contains an _id field, then the save() method is equivalent to an update with the upsert option set to true and the query predicate on the _id field. If _id filed is missing then save() is similar to insert()
{
scope: 'table',
table: 'YourCollectionName',
command: 'insert',
args:
{
doc:
{
_id : 1,
CustomerID : 'ALFKI',
CompanyName : 'Company 1-Updated',
RegistrationDate : ISODate('2001-01-01T00:00:00'),
ContactName : 'Maria1 Anders',
'Contact Title' : 'Sales Representative',
AddressInfo : { Address1: 'Obere Str. 57',City: 'Newyork',State: 'NY' } ,
Tags : ['aa','bb','cc']
}
}
}
Collection [Find]: Find records (with condition)
This example shows how to count total records with certain condition(s) for specific MongoDB collection.
{
scope: 'table',
table: 'YourCollectionName',
command: 'find',
args: {
query: { $or : [{country:'USA'},{country:'UK'}] }
}
}
Collection [Find]: Fetch all records
This example shows how to fetch all records for specified MongoDB collection.
{
scope: 'table',
table: 'YourCollectionName',
command: 'find'
}
Collection [Custom]: Fetch records using SQL query
This example shows how to use familiar SQL Query language to extract data from MongoDB collection. SQL query is translated to MongoDB Native query automatically so you don't have to learn MongoDB JSON Style query language.
SELECT top 10 *
FROM Customer
WHERE Country IN ('USA', 'Germany') AND CompanyName LIKE 'C%'
ORDER BY CustomerID DESC
Collection [Remove]: Remove records (with condition)
This example shows how to remove records from MongoDB collection based on certain condition(s).
{
scope: 'table',
table: 'YourCollectionName',
command: 'remove',
args:
{
query: { $or : [{country:'USA'},{country:'UK'}] }
}
}
Collection [RemoveAll]: Remove all records (Truncate table)
This example shows how to remove all records for specified MongoDB collection.
{
scope: 'table',
table: 'YourCollectionName',
command: 'removeAll'
}
Collection [GetStats]: Get collection statistics
This example shows how to fetch collection statistics.
{
scope: 'table',
table: 'YourCollectionName',
command: 'getStats'
}