Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ print(result?.insertedID ?? "") // prints `.int64(100)`
**Async**:
```swift
let query: BSONDocument = ["a": 1]
let result = collection.find(query).flatMap { cursor in
// 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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would be obvious from context what this is doing. maybe we could add a comment or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. I figure these examples will largely be used for copy/paste, so I included the comment in both examples to ensure it gets picked up regardless of how a user tries out the driver.

let result = collection.find(query, options: options).flatMap { cursor in
cursor.forEach { doc in
print(doc)
}
Expand All @@ -147,7 +151,11 @@ let result = collection.find(query).flatMap { cursor in
**Sync**:
```swift
let query: BSONDocument = ["a": 1]
let documents = try collection.find(query)
// 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 {
print(try d.get())
}
Expand Down