How to use MongoKitten 5 in sync way
sergeydi opened this issue · comments
Hi,
In previous versions of MongoKitten (<= 4) I use it like:
let document = try myCollection.findOne("_id" == objectId)
It works in sync way.
Can I continue using sync way in MongoKitten 5?
Good morning! We've moved to an asynchronous model for stability and performance, as well as it being the preferred way in Server-Side Swift now.
You can use Database.synchronousConnect(..)
to connect in synchronous environments and will have' to use .wait()
at the end of a query for synchronous execution.
If you want a fully synchronous client, without .wait()
, there are two good solutions that I can think of.
The first one is to wrap MongoKitten's Cluster, Database and Collection types with the same functions, but synchronous. The alternative is to wait for MongoKitten 6 and related libraries that will be released at the same time. They will support synchronous calls