-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridfs.js
More file actions
26 lines (21 loc) Β· 606 Bytes
/
gridfs.js
File metadata and controls
26 lines (21 loc) Β· 606 Bytes
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
// gridfs.js
const mongoose = require("mongoose");
const config = require('../config');
let gfs;
const initGridFS = () => {
const url = config.mongoURI;
const connect = mongoose.createConnection(url, { useNewUrlParser: true, useUnifiedTopology: true });
connect.once("open", () => {
gfs = new mongoose.mongo.GridFSBucket(connect.db, {
bucketName: "uploads"
});
});
return connect;
};
const getGridFS = () => {
if (!gfs) {
throw new Error("GridFS is not initialized yet");
}
return gfs;
};
module.exports = { initGridFS, getGridFS };