-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
49 lines (44 loc) · 1.45 KB
/
db.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
/**
* Created by shenshijun on 14-6-25.
*/
var mongodb = require("mongodb");
var db_server = new mongodb.Server("127.0.0.1", 27017);
var db = new mongodb.Db("android_back", db_server);
if ((typeof this.users === "undefined") || (typeof this.book_col === "undefined")) {
db.open(function (err, db) {
if (err) {
throw err;
}
db.collection("user", function (err, col) {
if (err) {
throw err;
}
col.ensureIndex({"username": 1},
{"unique": true, "background": true, "dropDups": true},
function (err, indexName) {
if (err) {
throw err;
}
col.ensureIndex({"create_time": 1},
{"background": true}, function (err, index_name) {
if (err) {
throw err;
}
exports.users = col;
});
});
});
db.collection("book_col", function (err, col) {
if (err) {
throw err;
}
col.ensureIndex({"book_id": 1},
{"background": true}, function (err, indexNamee) {
if (err) {
throw err;
}
exports.book_col = col;
});
});
});
}