-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
48 lines (32 loc) · 894 Bytes
/
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
/**
* Created by addison on 14-6-23.
*
* 创建数据库
*
*
*/
var Db = require('mongodb').Db,
Server = require('mongodb').Server;
var mongodb = require('mongodb');
var server = new Server('127.0.0.1', 27017, {auto_reconnect: true});
function createDB(dbName, collections) {
var db = new mongodb.Db(dbName, server, {safe: true});
db.open(function (err, db) {
if (!err) {
collections.forEach(function (item) {
db.createCollection(item, {safe: true}, function (err, collection) {
if (err) {
console.log(err);
} else {
console.log('create table ' + item + ' success');
}
})
})
} else {
console.log(err);
}
db.close();
})
}
function delDb(dbName) {
}