Over the last few weeks we’ve been showing you how you can use Internet of Things technology like Node-RED to connect to services and pull data into MongoDB. There is an easier way to populate your MongoDB databases though. Our clever friends at Zapier, the web automation service for businesses, have added a MongoDB connection to their platform.
The big difference between Zapier and other web automation services is their focus on non-developers. They have a simple interface which guides you through creating what they call “zaps”. You select the service you want to trigger the zap and what that trigger should be. Then you select the service you want to act on and what kind of action should take place. Zapier then guides you through the details required such as authorizing connections, selecting and filtering, creating message templates and the like, then generates some tests and, if all is good, allows you to save your completed zap. The trigger is then tested periodically, from five to fifteen minutes. The services list is already huge and include Google Mail, Calendar and Drive, Evernote. BaseCamp, Jira, Twitter, Salesforce and many more.
Zapier and MongoDB
One example use case we came up with was cataloging photos. Dropbox users will know they can have their photos automatically uploaded to the cloud storage platform. What if we could create a MongoDB database of uploaded photographs automatically. Zapier’s Dropbox connection can detect when files are added to a directory and its MongoDB connection can create a document in a collection, so if we select those options…
Zapier will now guide us through the other steps needed. This includes connecting to Dropbox and MongoDB accounts. (Tip: set up your MongoDB database first - Zapier probes for the existence of the database when you test the account). We can then filter the Dropbox events. As pictures are uploaded to the Camera Uploads directory, we tell it to monitor that directory – we could set up a more specific filter in Zapier as it has access to file size, URLs, paths, modified dates and mime types but for now, we want to record all the new photos uploaded.
Now we can create a MongoDB document , selecting the database and name of collection. If we don’t specify any fields, all the raw data Zapier has is copied across in the document, but you can also give field names and select particular items from that raw data as we do here.
And all that's left to do is to test the zap – Zapier finds sample data from the source to make that easier – give it a name and set it running. As we take photos and auto-upload them, the Zapier zap creates our document and after a while the collection starts building up:
Simple and effective. And it’s not just one way traffic. You can set up a zap that watches a MongoDB collection for new documents and trigger an action when they appear. It took just minutes to set a zap up to spot new photo documents in the database and send us a Google Talk message that told us the name of the file, a URL where we could view it and what its MIME type was.
Of course, this is only the start of what Zapier can do and combined with a database like MongoDB, you may find you don’t know where to start. The MongoDB Integrations page at Zapier offers up a range of zap templates that use MongoDB, so you can start archiving Stripe payments, Pingdom alerts, Gmail messages, RSS feeds, Github issues or HelpScout tickets quickly. The MongoDB integration can also trigger on more than just new documents being created; it can fire off when a new field is added to a document schema, when a new collection is added to a database or, depending on the MongoDB instance’s visibility, when a new database is added.
Get started with MongoHQ and Zapier today.