@@ -139,9 +139,41 @@ public struct MongoCollection<T: Codable> {
139139
140140 if self . readPreference != self . _client. readPreference {
141141 // there is no concept of an empty read preference so we will always have a value here.
142- mongoc_collection_set_read_prefs ( collection, self . readPreference. pointer)
142+ self . readPreference. withMongocReadPreference { rpPtr in
143+ mongoc_collection_set_read_prefs ( collection, rpPtr)
144+ }
143145 }
144146
145147 return try body ( collection)
146148 }
149+
150+ /// Internal method to check the `ReadConcern` that is set on `mongoc_collection_t`s via `withMongocCollection`.
151+ /// **This method may block and is for testing purposes only**.
152+ internal func getMongocReadConcern( ) throws -> ReadConcern ? {
153+ try self . _client. connectionPool. withConnection { conn in
154+ self . withMongocCollection ( from: conn) { collPtr in
155+ ReadConcern ( copying: mongoc_collection_get_read_concern ( collPtr) )
156+ }
157+ }
158+ }
159+
160+ /// Internal method to check the `ReadPreference` that is set on `mongoc_collection_t`s via `withMongocCollection`.
161+ /// **This method may block and is for testing purposes only**.
162+ internal func getMongocReadPreference( ) throws -> ReadPreference {
163+ try self . _client. connectionPool. withConnection { conn in
164+ self . withMongocCollection ( from: conn) { collPtr in
165+ ReadPreference ( copying: mongoc_collection_get_read_prefs ( collPtr) )
166+ }
167+ }
168+ }
169+
170+ /// Internal method to check the `WriteConcern` that is set on `mongoc_collection_t`s via `withMongocCollection`.
171+ /// **This method may block and is for testing purposes only**.
172+ internal func getMongocWriteConcern( ) throws -> WriteConcern ? {
173+ try self . _client. connectionPool. withConnection { conn in
174+ self . withMongocCollection ( from: conn) { collPtr in
175+ WriteConcern ( copying: mongoc_collection_get_write_concern ( collPtr) )
176+ }
177+ }
178+ }
147179}
0 commit comments