MongoDB¶
AMI supports MongoDB datasources, although this is not offered as a default option. If you require the MongoDB datasource adapter, please contact us at support@3forge.com.
Setting up the Adapter¶
- Unzip the MongoDB files assigned to you from the client portal and add them to your AMI library.
-
Add the following property to your datasource plugin adapter list in
local.properties
: -
Restart AMI. MongoDB should now be available under Dashboard -> Data Modeler -> Attach Datasource
-
Give your MongoDB Datasource a name and configure the URL. The URL should take the following format:
Querying MongoDB¶
The AMI MongoDB adapter can query a MongoDB datasource and output SQL tables. The general syntax for querying MongoDB is:
This can be done in any field that takes AmiScript.
Collections¶
Assuming you have collections established in MongoDB, you can query these tables in AMI.
For a trivial example, consider a collection, zipcodes
, with the following properties in MongoDB:
Then query this table in AMI:
Collections with Nested Fields¶
AMI supports querying of MongoDB collections with nested fields. Consider the collection myAccounts
with nested fields in the address
field:
To query this table in AMI, call the nested field from its parent field using dotconcatentation:
Using EVAL
Methods (Deprecated)¶
Previously, AMI MongoDB methods were supported using FROM EVAL
functionality. This has since been deprecated. Instead, AMI supports the following directives directly:
The general format for using MongoDB commands involves encapsulating your MongoDB sort command in a string followed by the AMIScript EXECUTE
statement:
MongoDB Directives Examples¶
The result of running the different supported MongoDB directives in AMI on a toy datamodel results in the following output:
Sort¶
This creates two tables, userSorted
and accountsSorted
with users sorted in alphabetical order, followed by city name in descending order.
Find¶
To find a given field, create a table in AMI then use the _find
directive:
This query will return a table with entries from a collection for a user named "Crouton."
Skip¶
To skip documents, create an AMI table with a MongoDB skip condition:
Where in the last example, the first row where age is less than or equal to 11 is skipped.