-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
executable file
·149 lines (124 loc) · 3.63 KB
/
sample.js
File metadata and controls
executable file
·149 lines (124 loc) · 3.63 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var api_key = 'YOUR-API-KEY';
var db = 'test';
var collection = 'chat';
var flybase = require('./flybase').init(db, collection, api_key);
flybase.push( {name:"node", text:"test"}, function(data){
console.log("pushed good");
});
var cb = function(object, error){
console.log( object );
};
console.log( 'connected to ' + flybase.toString() );
var params = {'limit': 20 };
flybase.documents(params, function(data, err) {
console.log ("Found " + data.count() + " records");
});
flybase.on('added', function (data) {
var message = data.value();
console.log( message.name+': '+message.text );
});
flybase.limitToLast(10).on('value', function (data) {
data.forEach( function( message ){
var message = message.value();
console.log( message.name+': '+message.text );
});
});
/*
flybase.collections( function(object, error){
console.log( object );
});
*/
/*
Get all documents
@collection {String}
@params {Object}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.documents(params, cb);
// Params options
// q<query> :: restrict results by the specified JSON query
// q = {} :: object
// where = {} :: object
// query = {} :: object
// s<sort> :: specify the order in which to sort each specified field (1- ascending; -1 - descending)
// s = {} :: object
// sort = {} :: object
// asc = ['name', 'age'] :: array
// desc = ['name', 'age'] :: array
// f<set of fields> :: specify the set of fields to include or exclude in each document (1 - include; 0 - exclude)
// f = {} :: object
// include = ['name', 'age'] :: array
// exclude = ['name', 'age'] :: array
// c<boolean> :: return the result count for this query
// c = true :: boolean
// count = true :: boolean
// fo<boolean> :: return a single document from the result set (same as findOne() using the mongo shell
// fo = true :: boolean
// first = true :: boolean
// sk<num results to skip> :: specify the number of results to skip in the result set; useful for paging
// sk = 10 :: number
// skip = 10 :: number
// l<limit> :: specify the limit for the number of results (default is 1000)
// l = 10 :: number
// take = 10 :: number
// max = 10 :: number
// top = 10 :: number
// limit = 10 :: number
// --------
// UPDATING
// --------
// m<boolean> :: update all documents
// m = true :: boolean
// all = true :: boolean
// update-all = true :: boolean
// u<boolean> :: insert the document defined in the request body if none match the specified query
// u = true :: boolean
// upsert = true :: boolean
// var params = { where: { age: 28 }, asc: ['age'] };
// flybase.documents('users', params, function(data) {
// });
/*
Insert document / documents
@collection {String}
@documents {Object or Object array}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.set(documents, cb);
// flybase.push(documents, cb);
// flybase.insert(documents, cb);
/*
Update document / documents
@collection {String}
@condition {Object or Object array}
@params {Object}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.update(condition, params, cb);
/*
Find document by Id
@collection {String}
@id {String or Number}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.findId(id, cb);
/*
Update document by Id
@collection {String}
@id {String or Number}
@document {Object}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.updateId(id, document, cb);
/*
Delete document by Id
@collection {String}
@id {String or Number}
@cb {Function} :: function(error, object)
return {Flybase}
*/
// flybase.deleteId(id, cb);