mongohs

package
v0.0.0-...-147f0cf Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mongohs with MongoDB based history mongoClient This implements the HistoryStore.proto API

Index

Constants

View Source
const TimeStampField = "timestamp"

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoBucket

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

func NewMongoBucket

func NewMongoBucket(clientID, bucketID string, collection *mongo.Collection) *MongoBucket

func (*MongoBucket) Close

func (bucket *MongoBucket) Close() (err error)

Close the bucket and release its resources

func (*MongoBucket) Cursor

func (bucket *MongoBucket) Cursor() (cursor bucketstore.IBucketCursor)

func (*MongoBucket) Delete

func (bucket *MongoBucket) Delete(key string) error

func (*MongoBucket) Get

func (bucket *MongoBucket) Get(key string) (val []byte, err error)

func (*MongoBucket) GetMultiple

func (bucket *MongoBucket) GetMultiple(keys []string) (docs map[string][]byte, err error)

func (*MongoBucket) ID

func (bucket *MongoBucket) ID() string

func (*MongoBucket) Info

func (bucket *MongoBucket) Info() (info *bucketstore.BucketStoreInfo)

func (*MongoBucket) Set

func (bucket *MongoBucket) Set(key string, doc []byte) error

func (*MongoBucket) SetMultiple

func (bucket *MongoBucket) SetMultiple(docs map[string][]byte) (err error)

type MongoBucketStore

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

MongoBucketStore uses MongoDB to mongoClient client buckets in a mongoDB database. This mongoClient uses a database per client and a collection for each bucket. Optionally a time-series collection can be used instead of a regular collection.

This implements the bucketstore.IBucketStore interface with the IBucket interface for each collection.

func NewMongoBucketStore

func NewMongoBucketStore(clientID, dbURL, pass string, useTimeSeries bool) *MongoBucketStore

NewMongoBucketStore creates a bucket store with the MongoDB backend. This is intended for basic key-value storage use.

clientID is used as the database name
dbURL and pass are used to connect to the database
useTimeSeries creates timeseries collections for buckets instead of regular buckets

func (*MongoBucketStore) Close

func (srv *MongoBucketStore) Close() error

Close disconnects from the DB server Call Connect to reconnect.

func (*MongoBucketStore) GetBucket

func (srv *MongoBucketStore) GetBucket(bucketID string) bucketstore.IBucket

GetBucket returns a bucket to use This creates a new collection if it doesn't yet exist.

func (*MongoBucketStore) Open

func (srv *MongoBucketStore) Open() (err error)

Open connects to the DB server. This will setup the database if the collections haven't been created yet. Connect must be called before any other method, including Setup or Delete

type MongoCursor

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

func NewMongoCursor

func NewMongoCursor(bucketID string, mongoCursor *mongo.Cursor) *MongoCursor

NewMongoCursor create a new bucket cursor for the mongo client. Cursor.Close() must be called to release the resources.

func NewKVCursor(bucket bucketstore.IBucket, orderedKeys []string, kvbtree btree.Map[string, []byte]) *MongoCursor {

func (*MongoCursor) BucketID

func (cursor *MongoCursor) BucketID() string

func (*MongoCursor) First

func (cursor *MongoCursor) First() (key string, value []byte, valid bool)

First moves the cursor to the first item

func (*MongoCursor) Last

func (cursor *MongoCursor) Last() (key string, value []byte, valid bool)

Last moves the cursor to the last item

func (*MongoCursor) Next

func (cursor *MongoCursor) Next() (key string, value []byte, valid bool)

Next increases the cursor position and return the next key and value If the end is reached the returned key is empty

func (*MongoCursor) NextN

func (cursor *MongoCursor) NextN(steps uint) (docs map[string][]byte, itemsRemaining bool)

NextN increases the cursor position N times and return the encountered key-value pairs

func (*MongoCursor) Prev

func (cursor *MongoCursor) Prev() (key string, value []byte, valid bool)

Prev decreases the cursor position and return the previous key and value If the head is reached the returned key is empty

func (*MongoCursor) PrevN

func (cursor *MongoCursor) PrevN(steps uint) (docs map[string][]byte, itemsRemaining bool)

PrevN decreases the cursor position N times and return the encountered key-value pairs

func (*MongoCursor) Release

func (cursor *MongoCursor) Release()

Release the cursor capability

func (*MongoCursor) Seek

func (cursor *MongoCursor) Seek(searchKey string) (key string, value []byte, valid bool)

Seek positions the cursor at the given searchKey. This implementation is brute force. It generates a sorted list of orderedKeys for use by the cursor. This should still be fast enough for most cases. (test shows around 500msec for 1 million orderedKeys).

BucketID to seach for. Returns and error if the bucket is not found
key is the starting point. If key doesn't exist, the next closest key will be used.

This returns a cursor with Next() and Prev() iterators

Jump to

Keyboard shortcuts

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