Documentation ¶
Index ¶
- type MongoDB
- func (m *MongoDB) Client() *mongo.Client
- func (m *MongoDB) Close() error
- func (m *MongoDB) Collection(name string) (*mongo.Collection, error)
- func (m *MongoDB) Collections() map[string]*mongo.Collection
- func (m *MongoDB) CollectionsAreExisting() bool
- func (m *MongoDB) Connect() error
- func (m *MongoDB) Context() context.Context
- func (m *MongoDB) CreateIndex(name, key string, order int) (string, error)
- func (m *MongoDB) Database() (*mongo.Database, error)
- func (m *MongoDB) DatabaseIsExisting() bool
- func (m *MongoDB) DeleteOne(name string, filter interface{}) (int64, error)
- func (m *MongoDB) EstimatedDocumentCount(name string) (int64, error)
- func (m *MongoDB) Find(name string, filter interface{}, docs *[]map[string]interface{}, ...) error
- func (m *MongoDB) FindOne(name string, filter interface{}, doc interface{}) error
- func (m *MongoDB) InsertMany(name string, docs []interface{}) error
- func (m *MongoDB) InsertOne(name string, doc interface{}) error
- func (m *MongoDB) Ping() error
- func (m *MongoDB) ReplaceOne(name string, filter interface{}, doc interface{}, upsert bool) (bool, error)
- func (m *MongoDB) SetCollections(names ...string) error
- func (m *MongoDB) SetDatabase(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
func Open ¶
Open create an instance to keep MongoDB info and connects to server. If names is specfied, the first one is database name, and others are collection names.
func (*MongoDB) Collection ¶ added in v0.7.0
func (m *MongoDB) Collection(name string) (*mongo.Collection, error)
Collection returns a specified collection.
func (*MongoDB) Collections ¶
func (m *MongoDB) Collections() map[string]*mongo.Collection
Collections returns all collections.
func (*MongoDB) CollectionsAreExisting ¶ added in v0.6.0
CollectionAreExisting return a boolt to indicate if all collections are existing.
func (*MongoDB) CreateIndex ¶ added in v0.8.0
CreateIndex creates an index on collection name.
func (*MongoDB) DatabaseIsExisting ¶ added in v0.6.0
DatabaseIsExisting return a bool to indicate if a database is existing.
func (*MongoDB) DeleteOne ¶
DeleteOne executes a delete command to delete at most one document from the specified collection.
func (*MongoDB) EstimatedDocumentCount ¶
EstimatedDocumentCount gets an estimated of the number of documents in the specified collection.
func (*MongoDB) Find ¶
func (m *MongoDB) Find( name string, filter interface{}, docs *[]map[string]interface{}, opts ...*options.FindOptions, ) error
Find stores the matching documents from the specified collection in a list.
func (*MongoDB) FindOne ¶
FindOne stores the matching document from the specified collection in an interface.
func (*MongoDB) InsertMany ¶ added in v0.9.0
InsertMany executes an insert command to insert multiple documents into the specified collection.
func (*MongoDB) InsertOne ¶
InsertOne executes an insert command to insert a single document into the specified collection.
func (*MongoDB) Ping ¶
Ping sends a ping command to verify that the client can connect to the deployment.
func (*MongoDB) ReplaceOne ¶
func (m *MongoDB) ReplaceOne( name string, filter interface{}, doc interface{}, upsert bool, ) (bool, error)
ReplaceOne executes an update command to replace at most one document in the specified collection. If upsert is true, a new document will be inserted if the filter does not match any documents in the collection.
func (*MongoDB) SetCollections ¶
SetCollections sets one or more collections.
func (*MongoDB) SetDatabase ¶
SetDatabase configures the database.