From aa8f47db1946f5351049eac02b61c37d63b0c9f5 Mon Sep 17 00:00:00 2001 From: Patrick Freed Date: Thu, 11 Feb 2021 15:35:55 -0500 Subject: [PATCH 1/2] add sort example --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ead7c33a..747c05179 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,8 @@ print(result?.insertedID ?? "") // prints `.int64(100)` **Async**: ```swift let query: BSONDocument = ["a": 1] -let result = collection.find(query).flatMap { cursor in +let options = FindOptions(sort: ["_id": -1]) +let result = collection.find(query, options: options).flatMap { cursor in cursor.forEach { doc in print(doc) } @@ -147,7 +148,8 @@ let result = collection.find(query).flatMap { cursor in **Sync**: ```swift let query: BSONDocument = ["a": 1] -let documents = try collection.find(query) +let options = FindOptions(sort: ["_id": -1]) +let documents = try collection.find(query, options: options) for d in documents { print(try d.get()) } From 997a6a5c33f570e5ebe3b19a6032ac147f588e41 Mon Sep 17 00:00:00 2001 From: Patrick Freed Date: Thu, 11 Feb 2021 18:06:43 -0500 Subject: [PATCH 2/2] add comment --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 747c05179..663d27560 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ print(result?.insertedID ?? "") // prints `.int64(100)` **Async**: ```swift let query: BSONDocument = ["a": 1] +// The `sort` option specifies the order in which results are returned +// via the cursor. In this case, `["_id": -1]` indicates that the documents will +// be returned in descending order according to the `_id` field. let options = FindOptions(sort: ["_id": -1]) let result = collection.find(query, options: options).flatMap { cursor in cursor.forEach { doc in @@ -148,6 +151,9 @@ let result = collection.find(query, options: options).flatMap { cursor in **Sync**: ```swift let query: BSONDocument = ["a": 1] +// The `sort` option specifies the order in which results are returned +// via the cursor. In this case, `["_id": -1]` indicates that the documents will +// be returned in descending order according to the `_id` field. let options = FindOptions(sort: ["_id": -1]) let documents = try collection.find(query, options: options) for d in documents {