File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,11 @@ print(result?.insertedID ?? "") // prints `.int64(100)`
137137** Async** :
138138``` swift
139139let query: BSONDocument = [" a" : 1 ]
140- let result = collection.find (query).flatMap { cursor in
140+ // The `sort` option specifies the order in which results are returned
141+ // via the cursor. In this case, `["_id": -1]` indicates that the documents will
142+ // be returned in descending order according to the `_id` field.
143+ let options = FindOptions (sort : [" _id" : -1 ])
144+ let result = collection.find (query, options : options).flatMap { cursor in
141145 cursor.forEach { doc in
142146 print (doc)
143147 }
@@ -147,7 +151,11 @@ let result = collection.find(query).flatMap { cursor in
147151** Sync** :
148152``` swift
149153let query: BSONDocument = [" a" : 1 ]
150- let documents = try collection.find (query)
154+ // The `sort` option specifies the order in which results are returned
155+ // via the cursor. In this case, `["_id": -1]` indicates that the documents will
156+ // be returned in descending order according to the `_id` field.
157+ let options = FindOptions (sort : [" _id" : -1 ])
158+ let documents = try collection.find (query, options : options)
151159for d in documents {
152160 print (try d.get ())
153161}
You can’t perform that action at this time.
0 commit comments