- Mongo Database is document-oriented database. Unlike the relational database, In the Mongo database, data will be stored in JSON-like documents. MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time. The primary key of each document in the collection will be stored in Object format.
- Using Apache Drill we can extract the data from MongoDB in a simple SQL query. Apache Drill supports a variety of NO-SQL databases like MongoDB, HBase etc..
- Create a mongo storage plugin to connect to the MongoDB and enter the MongoDB credentials like host, username, password
- Write a simple Select query from a collection
- In the above screenshot, we can observe that _id column showing data in object format.
- To get the data in String format from the object, change the value of below property to false in Drill Options
- Open Drill UI and click on options
- Search for the property “store.mongo.bson.record.reader” and change the value to “false”, click on Update.
- Now run the below query to fetch object ID from MongoDB as a String
- Now in the above screenshot, we can see the data displayed in a String format
Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.
Query: select _id, FirstName from mongo.Sample.Person
Here I have selected a primary key id column and first name column from the collection Person
Output:
In database we have data stored in object format like “ObjectId(“59f2c3eba83a576fe07c735c”)”. I want to extract “59f2c3eba83a576fe07c735c” using SQL query but the above query is returning value in object format like “[B@2bc4de3d”
Query: select `p`.`_id`.`$oid` , `p`.`FirstName` from mongo.Sample.Person p `_id`.`$oid` is a selector for the object Id to show the same in String format
Output:
Best Open Source Business Intelligence Software Helical Insight is Here
A Business Intelligence Framework
Best Open Source Business Intelligence Software Helical Insight is Here
A Business Intelligence Framework
In case if you have any query please get us at support@helicaltech.com
Thank you
Ramu Vudugula
BI Developer
Helical IT Solutions Pvt Ltd