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

Query Builder Syntax

panigrah opened this issue · comments

Hi, I am migrating to MongoKitten from a different library that had supported query chaining to create queries dynamically. I am struggling to figure out how best to do that in MongoKitten. So I could do something like

query = Query().where(field1, value1).where(field2, value2).where(field3, value3)

fieldN and the valueN would be dynamically provided by the user to create arbitrary filters.

Whats the best way to create this dynamically in MongoKitten.

thanks for the help.

We have the && and &&= operators for that

var query: Query = ("username" == "Panigrah" && "active" == true)

for (field, value) in queryMatches {
    query &&= (field == value)
}

collection.find(query).limit(25).skip(50).getAllResults()