mongodb

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

The accessory package provides a high level API for go object storage in databases (MongoDB).

Documents

Documents are mapped to collections through their type. The type must be a struct, and the struct must have a field which is a primitive.ObjectID or a string. Use struct tags to define which field is the key field. For example,

type Source struct {
	Id         string        `bson:"_id,omitempty"`
	Url        string        `bson:"url,unique"`
}

The bson tags should either contain metadata or '-' to skip the field in the MongoDB database. Use the following flags:

  • unique - The field is unique in the collection, and an index is generated for the field (This is not part of the underlying MongoDB driver)
  • index - An index is generated for the field (This is not part of the underlying MongoDB driver)
  • omitempty - The field is omitted from the document if it is empty

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCollection

func NewCollection(database *driver.Database, meta *meta, fn trace.Func) *collection

func NewCursor

func NewCursor(c *driver.Cursor, t reflect.Type) *cursor

func NewDatabase

func NewDatabase(conn *conn, name string, meta metaLookupFunc, trace trace.Func) *database

func NewFilter

func NewFilter() *filter

func NewMeta

func NewMeta(t reflect.Type, name string) *meta

func NewSort

func NewSort() *sort

func Open

func Open(ctx context.Context, url *url.URL, opts ...ClientOpt) (Conn, error)

Connect to MongoDB server

Types

type ClientOpt

type ClientOpt func(*conn) error

func OptCollection

func OptCollection(collection any, name string) ClientOpt

Set the default timeout

func OptDatabase

func OptDatabase(v string) ClientOpt

Set the current database

func OptTimeout

func OptTimeout(v time.Duration) ClientOpt

Set the default timeout

func OptTrace

func OptTrace(fn trace.Func) ClientOpt

Set the trace function

Jump to

Keyboard shortcuts

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