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 1deaf94 commit a2047b8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Sources/MongoDBModel/Predicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ public extension BSONDocument {
// { <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 {
predicate.modifier == nil else {
return nil
}
let valueBSON: BSON
switch predicate.right {
case .keyPath:
return nil
case let .attribute(value):
guard let bson = try? BSON(attributeValue: value) else {
return nil
}
valueBSON = bson
case let .relationship(value):
valueBSON = BSON(relationship: value)
}
self = [
keyPath.rawValue: .document([comparisonOperator.rawValue: valueBSON])]
}
Expand Down

0 comments on commit a2047b8

Please sign in to comment.