forked from moai/luamongo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mongo_dbclient.cpp
735 lines (619 loc) · 20.1 KB
/
mongo_dbclient.cpp
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
#include <client/dbclient.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)
#include <compat-5.1.h>
#endif
};
#include "utils.h"
#include "common.h"
using namespace mongo;
extern int cursor_create(lua_State *L, DBClientBase *connection, const char *ns,
const Query &query, int nToReturn, int nToSkip,
const BSONObj *fieldsToReturn, int queryOptions, int batchSize);
extern void lua_to_bson(lua_State *L, int stackpos, BSONObj &obj);
extern void bson_to_lua(lua_State *L, const BSONObj &obj);
extern void lua_push_value(lua_State *L, const BSONElement &elem);
DBClientBase* userdata_to_dbclient(lua_State *L, int stackpos)
{
// adapted from http://www.lua.org/source/5.1/lauxlib.c.html#luaL_checkudata
void *ud = lua_touserdata(L, stackpos);
if (ud == NULL)
luaL_typerror(L, stackpos, "userdata");
// try Connection
lua_getfield(L, LUA_REGISTRYINDEX, LUAMONGO_CONNECTION);
if (lua_getmetatable(L, stackpos))
{
if (lua_rawequal(L, -1, -2))
{
DBClientConnection *connection = *((DBClientConnection **)ud);
lua_pop(L, 2);
return connection;
}
lua_pop(L, 2);
}
else
lua_pop(L, 1);
// try ReplicaSet
lua_getfield(L, LUA_REGISTRYINDEX, LUAMONGO_REPLICASET); // get correct metatable
if (lua_getmetatable(L, stackpos))
{
if (lua_rawequal(L, -1, -2))
{
DBClientReplicaSet *replicaset = *((DBClientReplicaSet **)ud);
lua_pop(L, 2); // remove both metatables
return replicaset;
}
lua_pop(L, 2);
}
else
lua_pop(L, 1);
luaL_typerror(L, stackpos, LUAMONGO_DBCLIENT);
return NULL; // should never get here
}
/***********************************************************************/
// The following methods are common to all DBClients
// (DBClientConnection and DBClientReplicaSet)
/***********************************************************************/
/*
* created = db:ensure_index(ns, json_str or lua_table[, unique[, name]])
*/
static int dbclient_ensure_index(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
BSONObj fields;
try {
int type = lua_type(L, 3);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 3);
fields = fromjson(jsonstr);
} else if (type == LUA_TTABLE) {
lua_to_bson(L, 3, fields);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "ensure_index", e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
bool unique = lua_toboolean(L, 4);
const char *name = luaL_optstring(L, 5, "");
bool res = dbclient->ensureIndex(ns, fields, unique, name);
lua_pushboolean(L, res);
return 1;
}
/*
* ok,err = db:auth({})
* accepts a table of parameters:
* dbname database to authenticate (required)
* username username to authenticate against (required)
* password password to authenticate against (required)
* digestPassword set to true if password is pre-digested (default = true)
*
*/
static int dbclient_auth(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
luaL_checktype(L, 2, LUA_TTABLE);
lua_getfield(L, 2, "dbname");
const char *dbname = luaL_checkstring(L, -1);
lua_getfield(L, 2, "username");
const char *username = luaL_checkstring(L, -1);
lua_getfield(L, 2, "password");
const char *password = luaL_checkstring(L, -1);
lua_getfield(L, 2, "digestPassword");
bool digestPassword = lua_isnil(L, -1) ? true : lua_toboolean(L, -1);
lua_pop(L, 4);
std::string errmsg;
bool success = dbclient->auth(dbname, username, password, errmsg, digestPassword);
if (!success) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_CONNECTION_FAILED, errmsg.c_str());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* is_failed = db:is_failed()
*/
static int dbclient_is_failed(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
bool is_failed = dbclient->isFailed();
lua_pushboolean(L, is_failed);
return 1;
}
/*
* addr = db:get_server_address()
*/
static int dbclient_get_server_address(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
std::string address = dbclient->getServerAddress();
lua_pushstring(L, address.c_str());
return 1;
}
/*
* count,err = db:count(ns)
*/
static int dbclient_count(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
int count = 0;
try {
count = dbclient->count(ns);
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_COUNT_FAILED, e.what());
return 2;
}
lua_pushinteger(L, count);
return 1;
}
/*
* ok,err = db:insert(ns, lua_table or json_str)
*/
static int dbclient_insert(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
int type = lua_type(L, 3);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 3);
dbclient->insert(ns, fromjson(jsonstr));
} else if (type == LUA_TTABLE) {
BSONObj data;
lua_to_bson(L, 3, data);
dbclient->insert(ns, data);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_INSERT_FAILED, e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:insert_batch(ns, lua_array_of_tables)
*/
static int dbclient_insert_batch(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
luaL_checktype(L, 3, LUA_TTABLE);
try {
std::vector<BSONObj> vdata;
size_t tlen = lua_objlen(L, 3) + 1;
for (size_t i = 1; i < tlen; ++i) {
vdata.push_back(BSONObj());
lua_rawgeti(L, 3, i);
lua_to_bson(L, 4, vdata.back());
lua_pop(L, 1);
}
dbclient->insert(ns, vdata);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_INSERT_FAILED, e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* cursor,err = db:query(ns, lua_table or json_str or query_obj, limit, skip, lua_table or json_str, options, batchsize)
*/
static int dbclient_query(lua_State *L) {
int n = lua_gettop(L);
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
Query query;
if (!lua_isnoneornil(L, 3)) {
try {
int type = lua_type(L, 3);
if (type == LUA_TSTRING) {
query = fromjson(luaL_checkstring(L, 3));
} else if (type == LUA_TTABLE) {
BSONObj obj;
lua_to_bson(L, 3, obj);
query = obj;
} else if (type == LUA_TUSERDATA) {
void *uq = 0;
uq = luaL_checkudata(L, 3, LUAMONGO_QUERY);
query = *(*((Query **)uq));
} else {
throw(LUAMONGO_REQUIRES_QUERY);
}
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_QUERY_FAILED, e.what());
return 2;
} catch (const char *err) {
lua_pushnil(L);
lua_pushstring(L, err);
return 2;
}
}
int nToReturn = luaL_optint(L, 4, 0);
int nToSkip = luaL_optint(L, 5, 0);
const BSONObj *fieldsToReturn = NULL;
if (!lua_isnoneornil(L, 6)) {
fieldsToReturn = new BSONObj();
int type = lua_type(L, 6);
if (type == LUA_TSTRING) {
fieldsToReturn = new BSONObj(luaL_checkstring(L, 6));
} else if (type == LUA_TTABLE) {
BSONObj obj;
lua_to_bson(L, 6, obj);
fieldsToReturn = new BSONObj(obj);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
}
int queryOptions = luaL_optint(L, 7, 0);
int batchSize = luaL_optint(L, 8, 0);
int res = cursor_create(L, dbclient, ns, query, nToReturn, nToSkip,
fieldsToReturn, queryOptions, batchSize);
if (fieldsToReturn) {
delete fieldsToReturn;
}
return res;
}
/*
* ok,err = db:remove(ns, lua_table or json_str or query_obj)
*/
static int dbclient_remove(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
int type = lua_type(L, 3);
bool justOne = lua_toboolean(L, 4);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 3);
dbclient->remove(ns, fromjson(jsonstr), justOne);
} else if (type == LUA_TTABLE) {
BSONObj data;
lua_to_bson(L, 3, data);
dbclient->remove(ns, data, justOne);
} else if (type == LUA_TUSERDATA) {
Query query;
void *uq = 0;
uq = luaL_checkudata(L, 3, LUAMONGO_QUERY);
query = *(*((Query **)uq));
dbclient->remove(ns, query, justOne);
} else {
throw(LUAMONGO_REQUIRES_QUERY);
}
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_REMOVE_FAILED, e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:update(ns, lua_table or json_str or query_obj, lua_table or json_str, upsert, multi)
*/
static int dbclient_update(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
int type_query = lua_type(L, 3);
int type_obj = lua_type(L, 4);
bool upsert = lua_toboolean(L, 5);
bool multi = lua_toboolean(L, 6);
Query query;
BSONObj obj;
if (type_query == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 3);
query = fromjson(jsonstr);
} else if (type_query == LUA_TTABLE) {
BSONObj q;
lua_to_bson(L, 3, q);
query = q;
} else if (type_query == LUA_TUSERDATA) {
void *uq = 0;
uq = luaL_checkudata(L, 3, LUAMONGO_QUERY);
query = *(*((Query **)uq));
} else {
throw(LUAMONGO_REQUIRES_QUERY);
}
if (type_obj == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 4);
obj = fromjson(jsonstr);
} else if (type_obj == LUA_TTABLE) {
lua_to_bson(L, 4, obj);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
dbclient->update(ns, query, obj, upsert, multi);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_UPDATE_FAILED, e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:drop_collection(ns)
*/
static int dbclient_drop_collection(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
dbclient->dropCollection(ns);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "drop_collection", e.what());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:drop_index_by_fields(ns, json_str or lua_table)
*/
static int dbclient_drop_index_by_fields(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
BSONObj keys;
try {
int type = lua_type(L, 3);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 3);
keys = fromjson(jsonstr);
} else if (type == LUA_TTABLE) {
lua_to_bson(L, 3, keys);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
dbclient->dropIndex(ns, keys);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "drop_index_by_fields", e.what());
return 2;
} catch (const char *err) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:drop_index_by_name(ns, index_name)
*/
static int dbclient_drop_index_by_name(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
dbclient->dropIndex(ns, luaL_checkstring(L, 3));
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "drop_index_by_name", e.what());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* ok,err = db:drop_indexes(ns)
*/
static int dbclient_drop_indexes(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
dbclient->dropIndexes(ns);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "drop_indexes", e.what());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* res,err = (dbname, jscode[, args_table])
*/
static int dbclient_eval(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *dbname = luaL_checkstring(L, 2);
const char *jscode = luaL_checkstring(L, 3);
BSONObj info;
BSONElement retval;
BSONObj *args = NULL;
if (!lua_isnoneornil(L, 4)) {
try {
int type = lua_type(L, 4);
if (type == LUA_TSTRING) {
args = new BSONObj(luaL_checkstring(L, 4));
} else if (type == LUA_TTABLE) {
BSONObj obj;
lua_to_bson(L, 4, obj);
args = new BSONObj(obj);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "eval", e.what());
return 2;
} catch (const char *err) {
lua_pushnil(L);
lua_pushstring(L, err);
return 2;
}
}
bool res = dbclient->eval(dbname, jscode, info, retval, args);
if (!res) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "eval", info["errmsg"].str().c_str());
return 2;
}
if (args) {
delete args;
}
lua_push_value(L, retval);
return 1;
}
/*
* bool = db:exists(ns)
*/
static int dbclient_exists(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
bool res = dbclient->exists(ns);
lua_pushboolean(L, res);
return 1;
}
/*
* name = db:gen_index_name(json_str or lua_table)
*/
static int dbclient_gen_index_name(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
string name = "";
try {
int type = lua_type(L, 2);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 2);
name = dbclient->genIndexName(fromjson(jsonstr));
} else if (type == LUA_TTABLE) {
BSONObj data;
lua_to_bson(L, 2, data);
name = dbclient->genIndexName(data);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "gen_index_name", e.what());
return 2;
} catch (const char *err) {
lua_pushnil(L);
lua_pushstring(L, err);
return 2;
}
lua_pushstring(L, name.c_str());
return 1;
}
/*
* cursor = db:get_indexes(ns)
*/
static int dbclient_get_indexes(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
auto_ptr<DBClientCursor> autocursor = dbclient->getIndexes(ns);
DBClientCursor **cursor = (DBClientCursor **)lua_newuserdata(L, sizeof(DBClientCursor *));
*cursor = autocursor.get();
autocursor.release();
luaL_getmetatable(L, LUAMONGO_CURSOR);
lua_setmetatable(L, -2);
return 1;
}
/*
* res,err = db:mapreduce(jsmapfunc, jsreducefunc[, query[, output]])
*/
static int dbclient_mapreduce(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
const char *jsmapfunc = luaL_checkstring(L, 3);
const char *jsreducefunc = luaL_checkstring(L, 4);
BSONObj query;
if (!lua_isnoneornil(L, 5)) {
try {
int type = lua_type(L, 5);
if (type == LUA_TSTRING) {
const char *jsonstr = luaL_checkstring(L, 5);
query = fromjson(jsonstr);
} else if (type == LUA_TTABLE) {
lua_to_bson(L, 5, query);
} else {
throw(LUAMONGO_REQUIRES_JSON_OR_TABLE);
}
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "mapreduce", e.what());
return 2;
} catch (const char *err) {
lua_pushnil(L);
lua_pushstring(L, err);
return 2;
}
}
const char *output = luaL_optstring(L, 6, "");
BSONObj res = dbclient->mapreduce(ns, jsmapfunc, jsreducefunc, query, output);
bson_to_lua(L, res);
return 1;
}
/*
* ok,err = db:reindex(ns);
*/
static int dbclient_reindex(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
const char *ns = luaL_checkstring(L, 2);
try {
dbclient->reIndex(ns);
} catch (std::exception &e) {
lua_pushboolean(L, 0);
lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_CONNECTION, "reindex", e.what());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
/*
* db:reset_index_cache()
*/
static int dbclient_reset_index_cache(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
dbclient->resetIndexCache();
return 0;
}
// Method registration table for DBClients
extern const luaL_Reg dbclient_methods[] = {
{"auth", dbclient_auth},
{"count", dbclient_count},
{"drop_collection", dbclient_drop_collection},
{"drop_index_by_fields", dbclient_drop_index_by_fields},
{"drop_index_by_name", dbclient_drop_index_by_name},
{"drop_indexes", dbclient_drop_indexes},
{"ensure_index", dbclient_ensure_index},
{"eval", dbclient_eval},
{"exists", dbclient_exists},
{"gen_index_name", dbclient_gen_index_name},
{"get_indexes", dbclient_get_indexes},
{"get_server_address", dbclient_get_server_address},
{"insert", dbclient_insert},
{"insert_batch", dbclient_insert_batch},
{"is_failed", dbclient_is_failed},
{"mapreduce", dbclient_mapreduce},
{"query", dbclient_query},
{"reindex", dbclient_reindex},
{"remove", dbclient_remove},
{"reset_index_cache", dbclient_reset_index_cache},
{"update", dbclient_update},
{NULL, NULL}
};