mongo

package
v0.0.0-...-f767cfc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package mongo provides a MongoDB database repository implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMongoDB

func NewMongoDB(ctx context.Context, config Config) (*mongo.Database, error)

NewMongoDB returns a new instance of the *mongo.Database type using the provided configuration.

Types

type Config

type Config struct {
	Host     string // Host specifies the MongoDB server host.
	Port     string // Port specifies the MongoDB server port.
	Username string // Username specifies the username used to authenticate with the MongoDB server.
	Password string // Password specifies the password used to authenticate with the MongoDB server.
	Database string // Database specifies the name of the MongoDB database to use.
}

Config represents MongoDB configuration.

type NoteRepository

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

NoteRepository is a struct that provides methods for interacting with the MongoDB database.

func NewNoteRepository

func NewNoteRepository(db *mongo.Database, collection ...string) (*NoteRepository, error)

NewNoteRepository creates a new NoteRepository instance with a MongoDB collection.

func (NoteRepository) DeleteOne

func (r NoteRepository) DeleteOne(ctx context.Context, noteID string) error

DeleteOne deletes a note from the MongoDB collection. If no note with the specified ID is found, returns an error.

func (NoteRepository) FindMany

func (r NoteRepository) FindMany(ctx context.Context, userID string) ([]domain.Note, error)

FindMany finds all notes associated with a specific user in the MongoDB collection. If no notes are found, returns an error.

func (NoteRepository) FindManyAsync

func (r NoteRepository) FindManyAsync(ctx context.Context, userID string) (<-chan domain.Note, <-chan error)

func (NoteRepository) FindOne

func (r NoteRepository) FindOne(ctx context.Context, noteID string) (domain.Note, error)

FindOne finds a note with a specific ID in the MongoDB collection. If no note is found, returns an error.

func (NoteRepository) SaveOne

func (r NoteRepository) SaveOne(ctx context.Context, note domain.Note) error

SaveOne saves a note to the MongoDB collection. If a note with the same ID already exists, returns an error.

func (NoteRepository) UpdateOne

func (r NoteRepository) UpdateOne(ctx context.Context, note domain.Note) error

UpdateOne updates a note in the MongoDB collection. If no note with the specified ID is found, returns an error.

Jump to

Keyboard shortcuts

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