forked from fengnz/fengdoorbot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Database.js
38 lines (29 loc) · 843 Bytes
/
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
function debugDatabase(){
var collectionName = Const.updateTimeColl;
var data = {"x": 1}
//insertToDB(collectionName, data);
//
var result = getLatestItemFromColl(collectionName);
Logger.log(result);
}
function getLatestItemFromColl(coll){
var latestItems = mongo.get(coll, 'sort={$natural:-1}&pagesize=1');
if (latestItems.length > 0){
return latestItems[0];
}
return null;
}
function clearCollection(collectionName){
mongo.replace(collectionName, null, []);
}
// This function inserts a javascript object directly to a mongo db collection
function insertToDB(collectionName, data) {
if (collectionName && data){
mongo.insert(collectionName, data)
}
}
function getAllCollectionFromDB(collectionName){
var option = getGetOption();
var query = null;
return mongo.get(collectionName, query);
}