Skip to content

Commit 05b28b5

Browse files
author
Christian Hergert
committed
doc: update collection_find docs for how to specify $orderby
1 parent 8976ab7 commit 05b28b5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

doc/mongoc_collection_find.page

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ mongoc_collection_find (mongoc_collection_t *collection,
3737
<tr><td><p>skip</p></td><td><p>A uint32_t of number of documents to skip or 0.</p></td></tr>
3838
<tr><td><p>limit</p></td><td><p>A uint32_t of max number of documents to return or 0.</p></td></tr>
3939
<tr><td><p>batch_size</p></td><td><p>A uint32_t containing batch size of document result sets or 0 for default. Default is 100.</p></td></tr>
40-
<tr><td><p>query</p></td><td><p>A bson_t to execute.</p></td></tr>
40+
<tr><td><p>query</p></td><td><p>A bson_t containing the query and options to execute.</p></td></tr>
4141
<tr><td><p>fields</p></td><td><p>A bson_t containing fields to return or NULL.</p></td></tr>
4242
<tr><td><p>read_prefs</p></td><td><p>A <link xref="mongoc_read_prefs_t">mongoc_read_prefs_t</link> or NULL for default read preferences.</p></td></tr>
4343
</table>
4444
</section>
4545

4646
<section id="description">
4747
<title>Description</title>
48-
<p>This function shall execute a query on the underlying <code>collection</code>. The bson <code>query</code> is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation.</p>
48+
<p>This function shall execute a query on the underlying <code>collection</code>.</p>
49+
<p>If no options are necessary, <code>query</code> can simply contain a query such as <code>{a:1}</code>. If you would like to specify options such as a sort order, the query must be placed inside of <code>{"$query": {}}</code> as specified by the server documentation. See the example below for how to properly specify additional options to <code>query</code>.</p>
4950
</section>
5051

5152
<section id="return">
@@ -70,7 +71,8 @@ print_all_documents (mongoc_collection_t *collection)
7071
char *str;
7172
bson_t *query;
7273
73-
query = bson_new ();
74+
query = BCON_NEW ("$query", "{", "foo", BCON_INT32 (1), "}",
75+
"$orderby": "{", "foo", BCON_INT32 (-1), "}");
7476
cursor = mongoc_collection_query (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
7577
7678
while (mongoc_cursor_more (cursor) && mongoc_cursor_next (cursor, &doc)) {

0 commit comments

Comments
 (0)