-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMongo.js
38 lines (35 loc) · 971 Bytes
/
Mongo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { MongoClient, ObjectID } = require('mongodb')
const omit = require('rubico/omit')
/**
* @name Mongo
*
* @synopsis
* ```coffeescript [specscript]
* Mongo(uri `mongodb+srv://<user>:<password>@<host>/<db>`) -> Mongo
* ```
*
* @description
* Replace the following with your MongoDB deployment's connection string.
*
* Note: `uri` must include the database parameter `db`
*
* Node.js MongoDB Driver API Usage
* https://docs.mongodb.com/drivers/node/usage-examples
*
* Collection API
* http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html
*
* How to create a database
* https://stackoverflow.com/questions/35758008/create-database-node-js-with-mongodb
*/
const Mongo = function (options) {
const mongo = new MongoClient(options.uri, {
useUnifiedTopology: true,
keepAlive: true,
...omit(['name', 'uri'])(options),
})
mongo.ready = mongo.connect()
return mongo
}
Mongo.ObjectID = ObjectID
module.exports = Mongo