easymongo

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 5 Imported by: 0

README

Easy Mongo

Simple wraper for MongoDB

Features

Usage

The following samples will assist you to become as comfortable as possible with easymongo library.

// Import easymongo into your code and refer it as `easymongo`.
import "github.com/BrunoKrugel/easymongo"
Create Client
easyMongo.NewMongoInstance("uri", "db", "collection")
Simple FindOne
filter := bson.D{
    {Key: "id", Value: "123"},
}

easyMongo.NewMongoInstance("uri", "db", "collection").FindOne(filter)

Documentation

Overview

Package easymongo provides a simple and easy-to-use wrapper for MongoDB operations in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoInstance

type MongoInstance struct {
	// contains filtered or unexported fields
}

MongoInstance represents a MongoDB connection instance.

func New

func New(uri string, db string, collection string) *MongoInstance

New creates and returns a new instance of MongoInstance.

func NewStatic

func NewStatic(uri string, db string, collection string) *MongoInstance

NewStatic returns a singleton instance of MongoInstance.

func (*MongoInstance) Close

func (m *MongoInstance) Close()

Close disconnects the MongoDB client.

func (*MongoInstance) DeleteOne

func (m *MongoInstance) DeleteOne(filter bson.D) (*mongo.DeleteResult, error)

DeleteOne deletes a single document from the MongoDB collection based on the specified filter.

func (*MongoInstance) FindOne

func (m *MongoInstance) FindOne(filter bson.D) *mongo.SingleResult

FindOne retrieves a single document from the MongoDB collection based on the specified filter.

func (*MongoInstance) InsertMany

func (m *MongoInstance) InsertMany(documents []interface{}) (*mongo.InsertManyResult, error)

InsertMany inserts multiple documents into the MongoDB collection.

func (*MongoInstance) InsertOne

func (m *MongoInstance) InsertOne(document interface{}) (*mongo.InsertOneResult, error)

InsertOne inserts a single document into the MongoDB collection.

func (*MongoInstance) UpdateOne

func (m *MongoInstance) UpdateOne(filter bson.D, update bson.D) (*mongo.UpdateResult, error)

UpdateOne updates a single document in the MongoDB collection based on the specified filter and update.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL