Mitto v2.9 adds MongoDB as an IO job input. This means users can now pipe data from MongoDB to relational databases or flat files.
The Mitto MongoDB input works with all versions of MongoDB, so no need to upgrade to MongoDB enterprise specifically for analytics.
Example MongoDB collection
Here’s a simple MongoDB collection that we will use as our data source.
> db.users.find()
[
{
_id: ObjectId("603d70abad8c611758a46d11"),
name: 'Justin',
last_updated: 2021-03-01T22:59:31.828Z,
last_updated_string: '2021-03-01T22:59:31.828Z'
},
{
_id: ObjectId("603d713ead8c611758a46d12"),
name: 'Andy',
last_updated: 2021-03-01T22:59:24.635Z,
last_updated_string: '2021-03-01T22:59:24.635Z'
}
]
Example IO Job
Here’s a basic Mitto IO job that will copy the entire collection into Mitto’s PostgreSQL database:
{
input: {
use: nosql.mongodb#MongoDbInput
database: analytics
collection: users
host: mongodb://{username}:{password}@{server}
}
output: {
dbo: postgresql://localhost/analytics
schema: mongodb
tablename: users
use: call:mitto.iov2.db#todb
}
steps: [
{
transforms: [
{
use: mitto.iov2.transform#ExtraColumnsTransform
}
{
use: mitto.iov2.transform#ColumnsTransform
}
]
use: mitto.iov2.steps#Input
}
{
use: mitto.iov2.steps#CreateTable
}
{
transforms: [
{
use: mitto.iov2.transform#FlattenTransform
}
]
use: mitto.iov2.steps#Output
}
{
use: mitto.iov2.steps#CollectMeta
}
]
}
This input is the equivalent of this MongoDB query:
> db.users.find()
[
{
_id: ObjectId("603d70abad8c611758a46d11"),
name: 'Justin',
last_updated: 2021-03-01T22:59:31.828Z,
last_updated_string: '2021-03-01T22:59:31.828Z'
},
{
_id: ObjectId("603d713ead8c611758a46d12"),
name: 'Andy',
last_updated: 2021-03-01T22:59:24.635Z,
last_updated_string: '2021-03-01T22:59:24.635Z'
}
]
And here’s that MongoDB collection in a PostgreSQL database table:
Example IO Job using Find
Here’s another Mitto IO job that will copy a filtered collection into Mitto’s PostgreSQL database:
{
input: {
use: nosql.mongodb#MongoDbInput
database: analytics
collection: users
host: mongodb://root:zuar2021@db-do.zuar.com
find: {
name: Justin
}
}
output: {
dbo: postgresql://localhost/analytics
schema: mongodb
tablename: users_find
use: call:mitto.iov2.db#todb
}
steps: [
{
transforms: [
{
use: mitto.iov2.transform#ExtraColumnsTransform
}
{
use: mitto.iov2.transform#ColumnsTransform
}
]
use: mitto.iov2.steps#Input
}
{
use: mitto.iov2.steps#CreateTable
}
{
transforms: [
{
use: mitto.iov2.transform#FlattenTransform
}
]
use: mitto.iov2.steps#Output
}
{
use: mitto.iov2.steps#CollectMeta
}
]
}
Notice the only differences here are the find
parameter of the input
and the tablename
of the output
:
{
input: {
...
find: {
name: Justin
}
}
output: {
...
tablename: users_find
...
}
...
}
This input is the equivalent of this MongoDB query:
> db.users.find({'name': 'Justin'})
[
{
_id: ObjectId("603d70abad8c611758a46d11"),
name: 'Justin',
last_updated: 2021-03-01T22:59:31.828Z,
last_updated_string: '2021-03-01T22:59:31.828Z'
}
]
And here’s that MongoDB query in a PostgreSQL database table: