Skip to content

Commit 7cf514e

Browse files
author
Christian Hergert
committed
client: allow providing fully qualified namespace for $cmd.
1 parent 9c477d3 commit 7cf514e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/mongoc/mongoc-client.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,17 @@ mongoc_client_command (mongoc_client_t *client,
11581158
read_prefs = client->read_prefs;
11591159
}
11601160

1161-
bson_snprintf (ns, sizeof ns, "%s.$cmd", db_name);
1161+
/*
1162+
* Allow a caller to provide a fully qualified namespace. Otherwise,
1163+
* querying something like "$cmd.sys.inprog" is not possible.
1164+
*/
1165+
if (NULL == strstr (db_name, "$cmd")) {
1166+
bson_snprintf (ns, sizeof ns, "%s.$cmd", db_name);
1167+
db_name = ns;
1168+
}
11621169

1163-
return _mongoc_cursor_new (client, ns, flags, skip, limit, batch_size, true,
1164-
query, fields, read_prefs);
1170+
return _mongoc_cursor_new (client, db_name, flags, skip, limit, batch_size,
1171+
true, query, fields, read_prefs);
11651172
}
11661173

11671174

0 commit comments

Comments
 (0)