MongoDB interpreter for Apache Zeppelin.
Supported versions of MongoDB: >= 3.0
If you are interested, there is a Docker image for Zeppelin with MongoDB interpreter: https://hub.docker.com/r/cthiebault/zeppelin-mongodb/
Requirement: Zeppelin must be in your local repo.
mvn clean package
If you cannot build the jar, you can download it in the release page
$ZEPPELIN_HOME/conf/zeppeln-site.xml
<property>
<name>zeppelin.interpreters</name>
<value>...,org.apache.zeppelin.mongodb.MongoDbInterpreter</value>
</property>
$ZEPPELIN_HOME/interpreter/mongodb
$ZEPPELIN_HOME/interpreter/mongodb
In some cases, mongodb is not visible in the list of the available interpreters. In this case, after the previous steps, you can create a new interpreter and in the interpreter group selection, you should be able to select mongodb.
Parameter | Default value | Description |
---|---|---|
mongo.shell.path | mongo | Mongo shell path |
mongo.shell.command.timeout | 60000 | Mongo command timeout |
mongo.shell.command.table.limit | 1000 | Limit of documents displayed in a table |
mongo.server.database | test | MongDB database name |
mongo.server.host | localhost | Host of the MongDB server |
mongo.server.port | 27017 | Port of the MongDB server |
mongo.server.username | Username for authentication | |
mongo.server.password | Password for authentication | |
mongo.server.authentdatabase | Database used for authentication |
In Zeppelin, use %mongodb
in a paragraph.
After that, you can type the same Javascript code you use when you write scripts for the Mongo shell.
For more information, please consult: https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/
There are several functions that have been added to help you in Zeppelin:
%table
). Arguments:
Examples:
%mongodb
// Display a table
db.zipcodes.find({ "city":"CHICAGO", "state": "IL" }).table()
%mongodb
var states = db.zipcodes.aggregate( [
{ $group: { _id: "$state", totalPop: { $sum: "$pop" } } },
{ $match: { totalPop: { $lt: 1000*1000 } } },
{ $sort: { totalPop: 1 } }
] )
// Build a 'table'
print("%table state\ttotalPop")
states.forEach(state => { print(state._id + "\t" + state.totalPop) })
Configuration:
Queries (these examples come from: https://docs.mongodb.com/manual/tutorial/aggregation-zip-code-data-set/)