-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
39 lines (35 loc) · 959 Bytes
/
database.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
39
var MongoClient = require("mongodb").MongoClient;
var uri = "mongodb://localhost:27017";
let insert = (database, data) => {
MongoClient.connect(uri, { useNewUrlParser: true }, function (err, client) {
if (err) {
console.log(err);
} else {
const db = client.db("gene");
var collection = db.collection(database);
collection.insertMany(data);
client.close();
}
});
};
let readGenes = (database, cb) => {
MongoClient.connect(uri, { useNewUrlParser: true }, function (err, client) {
if (err) {
console.log(err);
} else {
const db = client.db("gene");
var collection = db.collection(database);
collection.find({}).toArray(function(err, result) {
if (err) throw err;
// console.log(result);
client.close();
cb(result);
});
}
});
}
// readGenes("complete_gene",(res)=>console.log(res));
module.exports = {
insert: insert,
readGenes
};