---
title: "Setting up Quasar with MongoDB"
canonical: "https://onesaitplatform-es.refined.site/space/OP/blog/11763713/Setting%20up%20Quasar%20with%20MongoDB"
format: markdown
---
In this post we are going to explain how to set up the last release of [Quasar](https://github.com/slamdata/quasar) with MongoDB.

As October 16-2018, the latest release of Quasar is [v40.0.0](https://github.com/slamdata/quasar/releases/latest)

# What you need:


- Java jdk 1.8+
- Quasar Web JAR: [https://github.com/slamdata/quasar/releases/download/v40.0.0/quasar-web-assembly-40.0.0.jar](https://github.com/slamdata/quasar/releases/download/v40.0.0/quasar-web-assembly-40.0.0.jar)
- Quasar MongoDB Plugin JAR: [https://github.com/slamdata/quasar/releases/download/v40.0.0/quasar-mongodb-internal-assembly-40.0.0.jar](https://github.com/slamdata/quasar/releases/download/v40.0.0/quasar-mongodb-internal-assembly-40.0.0.jar)

# Creating the directory structure


- Create a directory (f.e. ‘quasar’) that will hold the jars and configuration files needed.
- Inside this directory, create a subdirectory called ‘plugins’.
- Download the JARs and copy the ‘quasar-web-assembly-40.0.0.jar’ to ‘quasar’, and ‘quasar-mongodb-internal-assembly-40.0.0.jar’ to ‘quasar/plugins’.
- Create new file called ‘quasar-config.json’ inside ‘quasar’ with the following information:

```
{
  "server": {
    "port": 18200
  },
  "metastore": {
    "database": {
      "h2": {
        "location": "./quasar-metastore.db"
      }
    }
  },
  "mountings": {
    "/": {
      "mongodb": {
        "connectionUri": "mongodb://localhost:27017/"
      }
    }
  }
}
```

You can bind quasar to any free *port* in your machine, in this case we will use port 18200.

The *metastore* is the internal storage that Quasar will use for its operations (H2 instance). You can also configure for a PostgreSQL instance in case you have it, you will just have to change the *metastore* configuration as follows:

```
"metastore": {
    "database": {
      "postgresql": {
        "host": "localhost",
        "port": 5432,
        "database": "metastore",
        "userName": "postgres",
        "password": ""
      }
    }
  }
```

Lastly, the *mountings*, which in this case, we are using *mongodb* as mountKey. The configuration above will attempt to mount it in path '/', though you can change to whatever path you want, for example, to */usr/local *

**Note:** Take into account that changing this mount path will change the quasar REST endpoints, so better leave the configuration with path '/'. 

- Create a file with extension *‘.plugin’ *inside ‘quasar/plugins’, for example, *mongo.plugin, *with the following JSON:

```
{
	"main_jar" : "quasar-mongodb-internal-assembly-40.0.0.jar",
	"classpath" :[
		"quasar-mongodb-internal-assembly-40.0.0.jar"
	]
}
```

This JSON will be loaded by the Web jar, and it needs to reference the MongoDB Plugin JAR.


Following the steps above, you will end up with the following directory structure and files:

![image](media://a962e79e-68f9-4fa6-840b-ca3a5542b6c0)

# Launching Quasar Web assembly


- Open a shell
- Go to the Quasar directory
- Execute the following command to set up the metastore needed by Quasar.

```
java -jar quasar-web-assembly-40.0.0.jar initUpdateMetaStore -c quasar-config.json
```

- Execute the following command to launch Quasar

```
java -jar quasar-web-assembly-40.0.0.jar -c quasar-config.json -P plugins/
```

Now Quasar should be up and listening to port 18200

![image](media://9063c56d-3058-4b96-b66b-ea60bd399fa0)


# Testing Quasar


- Navigate to URL [http://localhost:18200/mount/fs](http://localhost:18200/mount/fs) within a browser, you should see something like this:

```
{ "mongodb": { "connectionUri": "mongodb://localhost:27017/" } }
```


- If you already have collections created in MongoDB, compile a query for any of them at

[http://localhost:18200/compile/fs/](http://localhost:18200/compile/fs/)[db]/?q=[query]


For example: [http://localhost:18200/compile/fs/onesaitplatform_rtdb/?q=SELECT+*+FROM+MentionsBW](http://localhost:18200/compile/fs/onesaitplatform_rtdb/?q=SELECT+*+FROM+MentionsBW) in my case will produce the following output:

```
{ "type": "mongodb", "physicalPlan": "db.MentionsBW.find();\n", "inputs": [ "/onesaitplatform_rtdb/MentionsBW" ] }
```


You can find the full REST API operations [here](https://github.com/slamdata/quasar/tree/backport/v20.14.16+).