forked from dapps-community/dapp-logistic-sample
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmongo.js
61 lines (47 loc) · 1.27 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const mongoose = require('mongoose');
let db = mongoose.connection;
module.exports.mongo = db;
const connectionString = `mongodb://localhost:27017/immla`;
const connect = function () {
if (db.readyState !== 0) {
return;
}
const opts = {
server: {
"auto_reconnect": true,
poolSize: 10,
socketOptions: {
keepAlive: true
}
},
db: {
numberOfRetries: 5,
retryMiliSeconds: 1000
}
};
mongoose.connect(connectionString, opts);
};
db.on('connected', function () {
console.log('Connected to mongo database: ', connectionString);
});
db.on('disconnected', function () {
console.error('Disconnected from mongo database: ', connectionString);
});
db.on('error', function (err) {
console.error('Error from mongo db');
console.error(err.stack.toString());
process.exit();
});
db.on('open', function () {
console.log('Open connection to mongo database: ', connectionString);
});
connect();
const userScheme = mongoose.Schema({
id: String,
password: String,
type: {type: String, default: "client"},
email: String,
token: String,
pubkey: String
});
module.exports.User = mongoose.model('User', userScheme);