forked from soywiz-archive/typescript-node-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.d.ts
297 lines (242 loc) · 12.7 KB
/
mongodb.d.ts
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
///<reference path='node.d.ts' />
declare module "mongodb" {
export class Server {
constructor (host: string, port: number, opts?: ServerOptions);
}
export class Db {
constructor (databaseName: string, serverConfig: Server, db_options?: DBOptions);
public db(dbName: string): Db;
public open(callback: (err : Error, db : Db) => void );
public close(forceClose?: bool, callback?: (err: any, result: any) => void );
public admin(callback: (err, result) => void ): any;
public collectionsInfo(collectionName: string, callback?: (err, result) => void );
public collectionNames(collectionName: string, options: any, callback?: (err, result) => void );
public collection(collectionName: string, callback: (err: any, collection: Collection) => void );
public collection(collectionName: string, options: MongoCollectionOptions, callback: (err: any, collection: Collection) => void );
public collections(callback: (err: any, collections: Collection[]) => void );
public eval(code: any, parameters: any[], options?: any, callback?: (err, result) => void );
//public dereference(dbRef: DbRef, callback: (err, result) => void);
public logout(options: any, callback?: (err, result) => void );
public logout(callback: (err, result) => void );
public authenticate(userName: string, password: string, callback?: (err, result) => void );
public authenticate(userName: string, password: string, options: any, callback?: (err, result) => void );
public addUser(username: string, password: string, callback?: (err, result) => void );
public addUser(username: string, password: string, options: any, callback?: (err, result) => void );
public removeUser(username: string, callback?: (err, result) => void );
public removeUser(username: string, options: any, callback?: (err, result) => void );
public createCollection(collectionName: string, callback?: (err: Error, result: Collection) => void );
public createCollection(collectionName: string, options: CollectionCreateOptions, callback?: (err, result) => void );
public command(selector: any, callback?: (err, result) => void );
public command(selector: any, options: any, callback?: (err, result) => void );
public dropCollection(collectionName: string, callback?: (err, result) => void );
public renameCollection(fromCollection: string, toCollection: string, callback?: (err, result) => void );
public lastError(options, connectionOptions, callback: (err, result) => void );
public previousError(options, callback: (err, result) => void );
// error = lastError
// lastStatus = lastError
public executeDbCommand(command_hash, callback?: (err, result) => void );
public executeDbCommand(command_hash, options, callback?: (err, result) => void );
public executeDbAdminCommand(command_hash, callback?: (err, result) => void );
public executeDbAdminCommand(command_hash, options, callback?: (err, result) => void );
public resetErrorHistory(callback?: (err, result) => void );
public resetErrorHistory(options, callback?: (err, result) => void );
public createIndex(collectionName, fieldOrSpec, options, callback);
public ensureIndex(collectionName, fieldOrSpec, options, callback);
public cursorInfo(options, callback);
public dropIndex(collectionName, indexName, callback);
public reIndex(collectionName, callback);
public indexInformation(collectionName, options, callback);
public dropDatabase(callback: (err, result) => void );
public stats(options, callback);
public _registerHandler(db_command, raw, connection, exhaust, callback);
public _reRegisterHandler(newId, object, callback);
public _callHandler(id, document, err);
public _hasHandler(id);
public _removeHandler(id);
public _findHandler(id): { id: string; callback: Function; };
public __executeQueryCommand(self, db_command, options, callback);
public DEFAULT_URL: string;
public connect(url: string, options: { uri_decode_auth?: bool; }, callback: (err, result) => void );
}
export class ObjectID {
constructor (s: string);
}
export interface SocketOptions {
//= set seconds before connection times out default:0
timeout?: number;
//= Disables the Nagle algorithm default:true
noDelay?: bool;
//= Set if keepAlive is used default:0 , which means no keepAlive, set higher than 0 for keepAlive
keepAlive?: number;
//= ‘ascii’|’utf8’|’base64’ default:null
encoding?: string;
}
export interface ServerOptions {
// - to reconnect automatically, default:false
auto_reconnect?: bool;
// - specify the number of connections in the pool default:1
poolSize?: number;
// - a collection of pr socket settings
socketOptions?: any;
}
export interface PKFactory {
counter: number;
createPk: () => number;
}
export interface DBOptions {
//- if true, use native BSON parser
native_parser?: bool;
//- sets strict mode , if true then existing collections can’t be “recreated” etc.
strict?: bool;
//- custom primary key factory to generate _id values (see Custom primary keys).
pk?: PKFactory;
//- generation of objectid is delegated to the mongodb server instead of the driver. default is false
forceServerObjectId?: bool;
//- specify the number of milliseconds between connection attempts default:5000
retryMiliSeconds?: number;
//- specify the number of retries for connection attempts default:3
numberOfRetries?: number;
//- enable/disable reaper (true/false) default:false
reaper?: bool;
//- specify the number of milliseconds between each reaper attempt default:10000
reaperInterval?: number;
//- specify the number of milliseconds for timing out callbacks that don’t return default:30000
reaperTimeout?: number;
//- driver expects Buffer raw bson document, default:false
raw?: bool;
}
export interface CollectionCreateOptions {
// {true | {w:n, wtimeout:n} | {fsync:true}, default:false}, executes with a getLastError command returning the results of the command on MongoDB.
safe?: bool;
// {Boolean, default:false}, serialize functions on the document.
serializeFunctions?: bool;
// {Boolean, default:false}, perform all operations using raw bson objects.
raw?: bool;
// object overriding the basic ObjectID primary key generation.
pkFactory?: PKFactory;
// {Boolean, default:false}, create a capped collection.
capped?: bool;
// {Number}, the size of the capped collection in bytes.
size?: number;
// {Number}, the maximum number of documents in the capped collection.
max?: number;
// {Boolean, default:false}, create an index on the _id field of the document, not created automatically on capped collections.
autoIndexId?: bool;
// {String}, the prefered read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
readPreference?: string;
}
export interface Collection {
//constructor (db: Db, collectionName: string, pkFactory, options);
insert(query: any, callback: (err: any, result: any) => void): void;
insert(query: any, options: { safe?: any; continueOnError?: bool; keepGoing?: bool; serializeFunctions?: bool; }, callback: (err: any, result: any) => void): void;
remove(selector, callback?: (err: any, result: any) => void);
remove(selector, options: { safe?: any; single?: bool; }, callback?: (err: any, result: any) => void);
rename(newName: String, callback?: (err, result) => void);
save(doc: any, callback : (err, result) => void);
save(doc: any, options: { safe: any; }, callback : (err, result) => void);
update(selector: any, document: any, callback?: (err: any, result: any) => void): void;
update(selector: any, document: any, options: { safe?; upsert?; multi?; serializeFunctions?; }, callback: (err: any, result: any) => void): void;
distinct(key: string, query: Object, callback: (err, result) => void);
distinct(key: string, query: Object, options: { readPreferences; }, callback: (err, result) => void);
count(callback: (err, result) => void);
count(query: Object, callback: (err, result) => void);
count(query: Object, options: { readPreferences; }, callback: (err, result) => void);
drop(callback?: (err, result) => void);
findAndModify(query: Object, sort: any[], doc: Object, callback: (err, result) => void);
findAndModify(query: Object, sort: any[], doc: Object, options: { safe: any; remove: bool; upsert: bool; new: bool; }, callback: (err, result) => void);
findAndRemove(query : Object, sort? : any[], callback?: (err, result) => void);
findAndRemove(query : Object, sort? : any[], options?: { safe; }, callback?: (err, result) => void);
find(callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, options: CollectionFindOptions, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, options: CollectionFindOptions, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, skip: number, limit: number, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, skip: number, limit: number, timeout: number, callback?: (err: any, result: Cursor) => void): Cursor;
findOne(callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, options: CollectionFindOptions, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, options: CollectionFindOptions, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, skip: number, limit: number, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, skip: number, limit: number, timeout: number, callback?: (err: any, result: any) => void): Cursor;
createIndex(fieldOrSpec, options: IndexOptions, callback: (err: Error, indexName: string) => void);
ensureIndex(fieldOrSpec, options: IndexOptions, callback: (err: Error, indexName: string) => void);
indexInformation(options, callback);
dropIndex(name, callback);
dropAllIndexes(callback);
// dropIndexes = dropAllIndexes
reIndex(callback);
mapReduce(map, reduce, options, callback);
group(keys, condition, initial, reduce, finalize, command, options, callback);
options(callback);
isCapped(callback);
indexExists(indexes, callback);
geoNear(x, y, options, callback);
geoHaystackSearch(x, y, options, callback);
indexes(callback);
aggregate(pipeline:any[], options, callback);
stats(options, callback);
hint;
}
export interface IndexOptions {
background?: bool;
dropDups?: bool;
sparse?: bool;
unique?: bool;
v?: number;
}
export class Cursor {
constructor (db, collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read, returnKey, maxScan, min, max, showDiskLoc, comment, awaitdata, numberOfRetries, dbName, tailableRetryInterval, exhaust, partial);
rewind() : Cursor;
toArray(callback: (err: any, results: any[]) => any) : void;
each(callback: (err: Error, item: any) => void) : void;
count(callback: (err: any, count: number) => void) : void;
sort(keyOrList : any, callback? : (err, result) => void): Cursor;
sort(keyOrList : String, direction : any, callback? : (err, result) => void): Cursor;
limit(limit: number, callback?: (err, result) => void): Cursor;
setReadPreference(readPreferences, tags, callback?): Cursor;
skip(skip: number, callback?: (err, result) => void): Cursor;
batchSize(batchSize, callback: (err, result) => void): Cursor;
nextObject(callback: (err:any, doc: any) => void);
explain(callback: (err, result) => void);
//stream(): CursorStream;
close(callback?: (err, result) => void);
isClosed(): Boolean;
static INIT;
static OPEN;
static CLOSED;
}
export interface CollectionFindOptions {
limit?;
sort?;
fields?;
skip?;
hint?;
explain?;
snapshot?;
timeout?;
tailtable?;
tailableRetryInterval?;
numberOfRetries?;
awaitdata?;
exhaust?;
batchSize?;
returnKey?;
maxScan?;
min?;
max?;
showDiskLoc?;
comment?;
raw?;
readPreferences?;
partial?;
}
export interface MongoCollectionOptions {
safe?: any;
serializeFunctions?: any;
raw?: bool;
pkFactory?: any;
readPreferences?: string;
}
}