Skip to content

Commit

Permalink
Fixed BSONDocument.init(predicate:)
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Aug 21, 2023
1 parent ad8b287 commit 1deaf94
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Sources/MongoDBModel/Predicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ public extension BSONDocument {

public extension BSONDocument {

init?(predicate: Comparison) {
init?(predicate: FetchRequest.Predicate.Comparison) {
// { <field>: { $eq: <value> } }
guard case let .keyPath(keyPath) = predicate.left,
let comparisonOperator = ComparisonQueryOperator(predicate: predicate.type),
case let .value(value) = predicate.right,
predicate.options.isEmpty,
predicate.modifier == nil,
let valueBSON = try? BSON(attributeValue: value) else {
return nil
}
}

public extension BSON {

init?(predicate: Expression) {
return nil
self = [
keyPath.rawValue: .document([comparisonOperator.rawValue: valueBSON])]
}
}

0 comments on commit 1deaf94

Please sign in to comment.