Skip to content

Commit

Permalink
simplified function
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Jul 8, 2023
1 parent 6df042c commit 6a6b09d
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions bsonkit/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var Missing = MissingType{}
// documents e.g. "foo.bar.baz" and numbers may be used to descend into arrays
// e.g. "foo.2.bar".
func Get(doc Doc, path string) interface{} {
value, _ := get(doc, path, false, false)
value, _ := get(*doc, path, false, false)
return value
}

Expand All @@ -30,7 +30,7 @@ func Get(doc Doc, path string) interface{} {
// all values.
func All(doc Doc, path string, compact, merge bool) (interface{}, bool) {
// get value
value, nested := get(doc, path, true, compact)
value, nested := get(*doc, path, true, compact)
if !nested || !merge {
return value, nested
}
Expand Down Expand Up @@ -79,15 +79,6 @@ func get(v interface{}, path string, collect, compact bool) (interface{}, bool)
}
}

// get document field (with pointer)
if doc, ok := v.(*bson.D); ok {
for _, el := range *doc {
if el.Key == key {
return get(el.Value, ReducePath(path), collect, compact)
}
}
}

// get array field
if arr, ok := v.(bson.A); ok {
// get indexed array element if number
Expand Down

0 comments on commit 6a6b09d

Please sign in to comment.