-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatedb.js
95 lines (81 loc) · 2.82 KB
/
platedb.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// var host = GLOBAL.mongoHost;
// var port = GLOBAL.mongoPort;
// var dbname = GLOBAL.mongoDBName;
// //var localstr = "mongodb://mongo:[email protected]:33757/heroku_app5057630";
// var localstr = "mongodb://localhost:27017/plate";
// var mongodb= require('mongodb'),
// server = new mongodb.Server(host, port, {
// auto_reconnect: true
// }),
// platedb = new mongodb.Db(dbname, server);
// // callback: (err, db)
// function openDatabase(callback) {
// platedb.open(function(err, db) {
// if (err)
// return callback(err);
// console.log('Database connected');
// return callback(null, db);
// });
// }
// // callback: (err, collection)
// function authenticate(db, username, password, callback) {
// db.authenticate(username, password, function(err, result) {
// if (err) {
// return callback (err);
// }
// if (result) {
// var collection = new mongodb.Collection(db, 'test');
// // always, ALWAYS return the error object as the first argument of a callback
// return callback(null, collection);
// } else {
// return callback (new Error('authentication failed'));
// }
// });
// }
// function runQuery(myCollection, query, options, nextFn) {
// this.openDatabase(function(err, db) {
// db.authenticate('','', function (err, authResult) {
// if (err) {
// return nextFn(err);
// }
// if (authResult) {
// }
// })
// mongo.connect(localstr, {}, function(error, database){
// database.open(function(err, db) {
// db.collection(myCollection, function(err, collection) {
// var optionsArray = {};
// if (typeof(options) != 'undefined') {
// optionsArray = options;
// } else {
// optionsArray['limit'] = 100;
// optionsArray['sort'] = {};
// optionsArray['sort']['_id']= -1;
// }
// optionsArray['slaveOk'] = true;
// collection.find(query, optionsArray, function (err, cursor){
// if (err) {
// console.log("error is: " + err);
// nextFn(err, null);
// }
// cursor.toArray(function(err, docs) {
// db.close();
// if (err || (docs.length == 0)) {
// nextFn(err, null);
// } else {
// console.log("found " + docs.length + " documents in " + myCollection);
// var queryResults = [];
// for(var i=0; i<docs.length; i++) {
// queryResults[queryResults.length] = docs[i];
// }
// nextFn(err, queryResults);
// }
// });
// });
// });
// });
// });
// }
// exports.openDatabase = openDatabase;
// exports.authenticate = authenticate;
// exports.runQuery = runQuery;