Documentation ¶
Overview ¶
Package mongodb contains an implementation of the `gokv.Store` interface for MongoDB.
Note: If you use a sharded cluster, you must use "_id" as the shard key! You should also use hashed sharding as opposed to ranged sharding to enable more evenly distributed data no matter how your key looks like.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = Options{ ConnectionString: "localhost", DatabaseName: "gokv", CollectionName: "item", Codec: encoding.JSON, }
DefaultOptions is an Options object with default values. ConnectionString: "localhost", DatabaseName: "gokv", CollectionName: "item", Codec: encoding.JSON
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a gokv.Store implementation for MongoDB.
func NewClient ¶
NewClient creates a new MongoDB client.
You must call the Close() method on the client when you're done working with it.
func (Client) Delete ¶
Delete deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".
func (Client) Get ¶
Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The key must not be "" and the pointer must not be nil.
type Options ¶
type Options struct { // Seed servers for the initial connection to the MongoDB cluster. // Format: [mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]. // E.g.: "localhost" (the port defaults to 27017). // Optional ("localhost" by default). // For a detailed documentation and more examples see https://github.com/mongodb/docs/blob/01fa14decadc116b09ecdeae049e6744f16bf97f/source/reference/connection-string.txt. // For the options you need to stick to the mgo documentation (the package that gokv uses) instead of the official MongoDB documentation: // https://github.com/globalsign/mgo/blob/113d3961e7311526535a1ef7042196563d442761/session.go#L236. ConnectionString string // The name of the database to use. // Optional ("gokv" by default). DatabaseName string // The name of the collection to use. // Optional ("item" by default). CollectionName string // Encoding format. // Optional (encoding.JSON by default). Codec encoding.Codec }
Options are the options for the MongoDB client.