func (d Doc) LookupErr(key ...string) (Val, error) {
	elem, err := d.LookupElementErr(key...)
	return elem.Value, err
}
LookupErr searches the document and potentially subdocuments or arrays for the
provided key. Each key provided to this method represents a layer of depth.
package bsonx
import (
	"bytes"
	"errors"
	"fmt"
	"go.mongodb.org/mongo-driver/bson/bsontype"
	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
var ErrNilDocument = errors.New("document is nil")
type KeyNotFound struct {
	Key   []string       
	Depth uint           
	Type  bsontype.Type  
}
func (knf KeyNotFound) Error() string {
	depth := knf.Depth
	if depth >= uint(len(knf.Key)) {
		depth = uint(len(knf.Key)) - 1
	}
	if len(knf.Key) == 0 {
		return "no keys were provided for lookup"
	}
	if knf.Type != bsontype.Type(0) {
		return fmt.Sprintf(`key "%s" was found but was not valid to traverse BSON type %s`, knf.Key[depth], knf.Type)
	}
	return fmt.Sprintf(`key "%s" was not found`, knf.Key[depth])
}
type Doc []Elem
func ReadDoc(b []byte) (Doc, error) {
	doc := make(Doc, 0)
	err := doc.UnmarshalBSON(b)
	if err != nil {
		return nil, err
	}
	return doc, nil
}
func (d Doc) Copy() Doc {
	d2 := make(Doc, len(d))
	copy(d2, d)
	return d2
}
func (d Doc) Append(key string, val Val) Doc {
	return append(d, Elem{Key: key, Value: val})
}
func (d Doc) Prepend(key string, val Val) Doc {
	return append(Doc{{Key: key, Value: val}}, d...)
}
func (d Doc) Set(key string, val Val) Doc {
	idx := d.IndexOf(key)
	if idx == -1 {
		return append(d, Elem{Key: key, Value: val})
	}
	d[idx] = Elem{Key: key, Value: val}
	return d
}
func (d Doc) IndexOf(key string) int {
	for i, e := range d {
		if e.Key == key {
			return i
		}
	}
	return -1
}
func (d Doc) Delete(key string) Doc {
	idx := d.IndexOf(key)
	if idx == -1 {
		return d
	}
	return append(d[:idx], d[idx+1:]...)
}
func (d Doc) Lookup(key ...string) Val {
	val, _ := d.LookupErr(key...)
	return val
}