mod_mongo: add support for query options
This commit is contained in:
parent
e603c17de8
commit
b90f2446d4
|
@ -43,6 +43,33 @@ static struct {
|
|||
char *finalize;
|
||||
} globals;
|
||||
|
||||
static int parse_query_options(char *query_options_str)
|
||||
{
|
||||
int query_options = 0;
|
||||
if (strstr(query_options_str, "cursorTailable")) {
|
||||
query_options |= QueryOption_CursorTailable;
|
||||
}
|
||||
if (strstr(query_options_str, "slaveOk")) {
|
||||
query_options |= QueryOption_SlaveOk;
|
||||
}
|
||||
if (strstr(query_options_str, "oplogReplay")) {
|
||||
query_options |= QueryOption_OplogReplay;
|
||||
}
|
||||
if (strstr(query_options_str, "noCursorTimeout")) {
|
||||
query_options |= QueryOption_NoCursorTimeout;
|
||||
}
|
||||
if (strstr(query_options_str, "awaitData")) {
|
||||
query_options |= QueryOption_AwaitData;
|
||||
}
|
||||
if (strstr(query_options_str, "exhaust")) {
|
||||
query_options |= QueryOption_Exhaust;
|
||||
}
|
||||
if (strstr(query_options_str, "partialResults")) {
|
||||
query_options |= QueryOption_PartialResults;
|
||||
}
|
||||
return query_options;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(mongo_mapreduce_function)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
@ -101,11 +128,11 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_STANDARD_API(mongo_find_one_function)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
char *ns = NULL, *json_query = NULL, *json_fields = NULL;
|
||||
char *ns = NULL, *json_query = NULL, *json_fields = NULL, *query_options_str = NULL;
|
||||
int query_options = 0;
|
||||
|
||||
ns = strdup(cmd);
|
||||
switch_assert(ns != NULL);
|
||||
|
@ -114,6 +141,12 @@ SWITCH_STANDARD_API(mongo_find_one_function)
|
|||
*json_query++ = '\0';
|
||||
if ((json_fields = strchr(json_query, DELIMITER))) {
|
||||
*json_fields++ = '\0';
|
||||
if ((query_options_str = strchr(json_fields, DELIMITER))) {
|
||||
*query_options_str++ = '\0';
|
||||
if (!zstr(query_options_str)) {
|
||||
query_options = parse_query_options(query_options_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +160,7 @@ SWITCH_STANDARD_API(mongo_find_one_function)
|
|||
|
||||
conn = mongo_connection_pool_get(globals.conn_pool);
|
||||
if (conn) {
|
||||
BSONObj res = conn->findOne(ns, Query(query), &fields);
|
||||
BSONObj res = conn->findOne(ns, Query(query), &fields, query_options);
|
||||
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_FALSE);
|
||||
|
||||
stream->write_function(stream, "-OK\n%s\n", res.jsonString().c_str());
|
||||
|
|
Loading…
Reference in New Issue