-
Notifications
You must be signed in to change notification settings - Fork 9
/
init-database.js
71 lines (43 loc) · 1.17 KB
/
init-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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
autoIncrement = require('mongoose-auto-increment');
var connection = mongoose.createConnection("mongodb://localhost/myDatabase");
autoIncrement.initialize(connection);
var submitSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
outputName: String,
// genre: String,
publishDate: Date
});
submitSchema.plugin(autoIncrement.plugin, 'Submit');
var Submit = connection.model('Submit', submitSchema);
function getNextCount(callback) {
Submit.nextCount(function(err, count) {
// count === 0 -> true
console.log("counter: ", count);
var submit = new Submit();
submit.save(function(err) {
// submit._id === 0 -> true
if(err)
{
console.log(`error: updating the autoIncrement value of the submit collection =>\n count = ${count}`);
}
else{
console.log("counter: ", count);
callback(count);
//return count;
}
// submit.nextCount(function(err, count) {
// count === 1 -> true
// console.log("counter: ", count);
// });
});
});
}
// getNextCount();
module.exports = {
getNextCounter: getNextCount
}