-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb2.js
80 lines (56 loc) · 1.4 KB
/
db2.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
72
73
74
75
76
77
78
79
80
var mongodb = require('mongodb');
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
var server = new mongodb.Server('localhost','27017',{safe:false},{auto_reconnect: true},{j:true},{w:n, wtimeout:n}, {fsync:true});
exports.getAll = function(course,batch,callback){
var getAllDb =new mongodb.Db(course,server);
getAllDb.open(function(err, getAllDb) {
if (!err) {
this.getAllDb.collection(batch, function(err, collection) {
collection.find().toArray(function(err, docs) {
if (err) { callback(err);}
else {callback(docs);}
});
});
}
else {callback(err);}
});
getAllDb.close();
};
exports.getOne = function(course,batch,query,projection,callback) {
var getOneDb =new mongodb.Db(course,server);
getOneDb.open(function(err, getOneDb) {
if (!err) {
getOneDb.collection(batch, function(err, collection) {
collection.findOne(query,projection, function(err, doc) {
if (err) {callback(err);}
else{callback(doc);}
});
});
}
else{callback(err);}
});
getOneDb.close();
};
/*var info=require("./db2.js");
info.getAll('users','users',function(err,docs) {
if(!err)
{
console.log(docs);
}
else
{
console.log(err);
}
});*/
info.getOne('users','users',{"uid" : "rick"},{fields:{pass:1}},function(err,doc) {
if(!err)
{
console.log(docs);
}
else
{
console.log(err);
}
});
// exports.info();*/