bson.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (C) MongoDB, Inc. 2017-present.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Based on gopkg.in/mgo.v2/bson by Gustavo Niemeyer
  8. // See THIRD-PARTY-NOTICES for original license terms.
  9. package bson // import "go.mongodb.org/mongo-driver/bson"
  10. import (
  11. "go.mongodb.org/mongo-driver/bson/primitive"
  12. )
  13. // Zeroer allows custom struct types to implement a report of zero
  14. // state. All struct types that don't implement Zeroer or where IsZero
  15. // returns false are considered to be not zero.
  16. type Zeroer interface {
  17. IsZero() bool
  18. }
  19. // D is an ordered representation of a BSON document. This type should be used when the order of the elements matters,
  20. // such as MongoDB command documents. If the order of the elements does not matter, an M should be used instead.
  21. //
  22. // A D should not be constructed with duplicate key names, as that can cause undefined server behavior.
  23. //
  24. // Example usage:
  25. //
  26. // bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
  27. type D = primitive.D
  28. // E represents a BSON element for a D. It is usually used inside a D.
  29. type E = primitive.E
  30. // M is an unordered representation of a BSON document. This type should be used when the order of the elements does not
  31. // matter. This type is handled as a regular map[string]interface{} when encoding and decoding. Elements will be
  32. // serialized in an undefined, random order. If the order of the elements matters, a D should be used instead.
  33. //
  34. // Example usage:
  35. //
  36. // bson.M{"foo": "bar", "hello": "world", "pi": 3.14159}
  37. type M = primitive.M
  38. // An A is an ordered representation of a BSON array.
  39. //
  40. // Example usage:
  41. //
  42. // bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}}
  43. type A = primitive.A