orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift
MIT License
717 stars 102 forks source link

Whether to support native query #333

Closed onlw closed 9 months ago

onlw commented 9 months ago

like

query(db.collection.aggregate([ { $group: { _id: { machineId: "$machine.id", reportMonth: "$report_month" }, totalValue: { $sum: "$value" } } }, { $match: { totalValue: { $gt: 1 } } } ]))

Joannis commented 9 months ago

You can use .buildAggregate to construct a pipeline using result builders. Then you can add your own AggregateState, an example of which is the implementation of $match right underneath

https://github.com/orlandos-nl/MongoKitten/blob/main/Sources/MongoKitten/AggregateStage.swift#L7C17-L29

onlw commented 9 months ago

You can use .buildAggregate to construct a pipeline using result builders. Then you can add your own AggregateState, an example of which is the implementation of $match right underneath

https://github.com/orlandos-nl/MongoKitten/blob/main/Sources/MongoKitten/AggregateStage.swift#L7C17-L29

Thanks for your reply, in fact, I am going to make a mongo GUI tool, the commands are assembled by the user

Joannis commented 9 months ago

@onlw using SwiftUI? I've had a similar tool as well :)

onlw commented 9 months ago

@onlw using SwiftUI? I've had a similar tool as well :)

yeah, SwiftUI, It seems that I didn't find the tool