orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where is DBRef referenced in mongokitten.openkitten.org/Structs/DBRef.html?

MadGeorge opened this issue · comments

Hello. I found DBRef structure on http://mongokitten.openkitten.org/Structs/DBRef.html but can not find it in current API. How to use it?

These docs are quite old. Although large parts of the API have carried over to newer MongoKitten versions, I'm afraid this one did not. The sourcecode isn't too exciting, so you could be well off making one in your own application.

This is the original source code: https://github.com/OpenKitten/MongoKitten/blob/master/4.1/Sources/MongoKitten/Querying/DBRef.swift#L14

Although this would need to be adapted if used in Codable.

Every major release we remove features that we don't believe people ended up liking/using. This was one of them, and you're the first one in about 2-3 years that mentioned this :)

Most people seem to prefer a hard _id as a reference instead of a DBRef. DBRef's advantage is that it's agnostic to the collection, so you just fetch a Document from somewhere else in the DB. This doesn't really seem to be a nice solution when you need to unwrap it in Codable, so I'd prefer working on a different solution instead for MongoKitten.

I see. It looks like i will use manual referencing then.
Thank you for the answer.

I don't think this is something we'll be able to fit into the MongoKitten APIs. There's no knowledge of Models, and storing the other model's _id requires making the type generic or accepting any primitive. Neither are optimal, and we'd end up with 2 implementations.