Hi guys,
Today, we will see how to query the mongodb using apache drill sql interface. Apache drill provides ANSI SQL language for query data from any data source. We will use it to query mongodb.
If you don’t have mongodb and apache drill on your machine, then follow the below link before going further.
a) https://ranafaisal.wordpress.com/2015/05/13/install-mongodb-on-ubuntu-14-04/
b) https://ranafaisal.wordpress.com/2015/05/13/install-apache-drill-on-ubuntu-14-04/
Now lets start
1) Run apache drill shell “bin/sqlline -u jdbc:drill:zk=local”
2) Open WEB UI to enable MongoDB driver, URL of web UI is “http://localhost:8047”
3) Now click on storage link
4) In storage , find mongodb and click on update
5) Add the following info in the textbox
{
“type”: “mongo”,
“connection”: “mongodb://localhost:27017/”,
“enabled”: true
}
6) Then click Update button to enable this driver
7) On apache drill shell, run “show databases;“, this will also display the mongodb databases too.
8) Now lets query zips collection, “select * from mongo.mydb.zips;“, it will display all zips codes save in zips collection.
Cheers