# zeppelin-mongodb-interpreter **Repository Path**: tufeiping/zeppelin-mongodb-interpreter ## Basic Information - **Project Name**: zeppelin-mongodb-interpreter - **Description**: MongoDB interpreter for Apache Zeppelin - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-08-15 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # zeppelin-mongodb-interpreter 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/ ## Build Requirement: Zeppelin must be in your local repo. ```sh mvn clean package ``` ## Download If you cannot build the jar, you can download it in the [release page](https://github.com/bbonnin/zeppelin-mongodb-interpreter/releases) ## Deployment * Update `$ZEPPELIN_HOME/conf/zeppeln-site.xml` ```xml zeppelin.interpreters ...,org.apache.zeppelin.mongodb.MongoDbInterpreter ``` * Create `$ZEPPELIN_HOME/interpreter/mongodb` * Copy interpreter jar in `$ZEPPELIN_HOME/interpreter/mongodb` ## Configuration
ParameterDefault valueDescription
mongo.shell.pathmongoMongo shell path
mongo.shell.command.timeout60000Mongo command timeout
mongo.shell.command.table.limit1000Limit of documents displayed in a table
mongo.server.databasetestMongDB database name
mongo.server.hostlocalhostHost of the MongDB server
mongo.server.port27017Port of the MongDB server
mongo.server.usernameUsername for authentication
mongo.server.passwordPassword for authentication
mongo.server.authentdatabaseDatabase used for authentication
## How to use 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: * printTable(cursor, fields, flattenArray): to print a table (i.e. it uses `%table`). Arguments: * cursor: a DBQuery or DBCommandCursor instance * fields: an array of field names to put in the table (can be null) * flattenArray: if true, the arrays in the documents will also be flatten (false by default) * DBQuery.prototype.table: to print a table (it invokes the previous function) * DBCommandCursor.prototype.table: same as above Examples: ```javascript %mongodb // Display a table db.zipcodes.find({ "city":"CHICAGO", "state": "IL" }).table() ``` ```javascript %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) }) ``` ## Examples * Configuration: ![Configuration](docs/zeppelin-mongo-config.png) * Queries (these examples come from: https://docs.mongodb.com/manual/tutorial/aggregation-zip-code-data-set/) ![Examples](docs/zeppelin-mongo-examples.png)