Skip to content

More Mongo

Rhydderchc edited this page Feb 10, 2021 · 2 revisions

How to connect

You can connect to MongoDB using the database constructor in the hive.mongo adapter.

const hive = require('hive-db');
const {database} = hive.mongo;
const db = new database("mongodb+srv://wyvern:thebestbot@cluster0.67lsz.mongodb.net", "JSON", {useUnique: True})

What does this mean?

The database constructor initializes the mongodb connection using the uri. The JSON parameter helps it recognize the data if stored in json. It can be left default if you don't want to actually use JSON, it won't harm. The UseUnique param on the other hand asks if the data should be checked for its uniqueness, i.e., every data in each and every key is different from each other. And that's pretty much it for the definition of the connection module.

Beware!

Please do not remove the {} from the database initialization, this will result in an error. The {}, shows that database is a constructor and not a normal constant or variable. Err

Some more errors

There are ping or latency issues with mongodb, which is not an issue of hive-db's. Its something with your database uri.

Localhost

If your planning to use mongodb localhost with hive-db it'll work fine, although there are some incidents where you don't require your port, just the address. You can try it with a port as well, of course this is a hit and try case.

Clone this wiki locally