go-update-mongo

module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0

README

Go-Update-Mongo

Go-Update-Mongo is a small go library that wraps the FerretDB internals to provide a UpdateDocument function:

func UpdateDocument(document, updateDoc bson.D) (updatedDocument bson.D, err error) {}

The goal of this is to allow applications to perform complex operations on their data through mongo update operations rather than through functions. This is rarely better than a custom update function, however, if you want users to be able to update data on your platform, go-update-mongo allows you to accept user-input in the form of mongo update operations and run them in-memory rather than in a mdb database.

Current failure areas:

$(update) Unimplemented in FerretDB

$[] Unimplemented in FerretDB

$<identifier> FerretDB doesn't support ArrayFilters yet

$position, $slice, $sort They don't break the query but they don't work perfectly either. $position also has trouble with negative values

$setOnInsert partially works, however it is untested because I have a hard time determining exactly what the correct behavior should be here (because we are always performing an upsert action)

$pull with condition. Pull works on basic operations but it fails if you try to pull all documents that match a condition.

Testing Methodology

Testing is performed by inserting an object in mongo, running updateOne() on it, and verifying that the document is identical to the document produced by UpdateDocument

There are currently 205 tests and 61 are skipped.

It is worth it to scan through update/lib_test.go to determine if your use case can be satisfied with the library at this point in time

Running tests locally

Run make up-test-mongo to start a local mongodb docker container that the tests will run against. Then, run go test ./update/... --count 1 to run the tests.

Ferret Internals

Commit: 282c8e16c458537758fb7f4c64c614c84df45ba3 
Commit time: Thu Feb 8 10:09:09 2024 +0400

Steps to bring in a new version are avaiable at internal/README.md

Their tests do not pass in this repo because I have not set up the infra for their e2e tests

Directories

Path Synopsis
internal
ferret/backends
Package backends provides common interfaces ([Backend], [Database], and [Collection]) and code for all backend implementations.
Package backends provides common interfaces ([Backend], [Database], and [Collection]) and code for all backend implementations.
ferret/backends/decorators/dummy
Package dummy provides decorators that delegate all methods to wrapped objects.
Package dummy provides decorators that delegate all methods to wrapped objects.
ferret/backends/decorators/oplog
Package oplog provides decorators that add OpLog functionality to the backend.
Package oplog provides decorators that add OpLog functionality to the backend.
ferret/backends/hana
Package hana provides backend for SAP HANA.
Package hana provides backend for SAP HANA.
ferret/backends/mysql
Package mysql provides backend for MySQL and compatible databases.
Package mysql provides backend for MySQL and compatible databases.
ferret/backends/mysql/metadata
Package metadata provides access to databases and collections information.
Package metadata provides access to databases and collections information.
ferret/backends/mysql/metadata/pool
Package pool provides access to MySQL connections.
Package pool provides access to MySQL connections.
ferret/backends/postgresql
Package postgresql provides backend for PostgreSQL and compatible databases.
Package postgresql provides backend for PostgreSQL and compatible databases.
ferret/backends/postgresql/metadata
Package metadata provides access to databases and collections information.
Package metadata provides access to databases and collections information.
ferret/backends/postgresql/metadata/pool
Package pool provides access to PostgreSQL connections.
Package pool provides access to PostgreSQL connections.
ferret/backends/sqlite
Package sqlite provides SQLite backend.
Package sqlite provides SQLite backend.
ferret/backends/sqlite/metadata
Package metadata provides access to databases and collections information.
Package metadata provides access to databases and collections information.
ferret/backends/sqlite/metadata/pool
Package pool provides access to SQLite databases and their connections.
Package pool provides access to SQLite databases and their connections.
ferret/bson
Package bson provides converters from/to BSON for built-in and `types` types.
Package bson provides converters from/to BSON for built-in and `types` types.
ferret/bson2
Package bson2 implements encoding and decoding of BSON as defined by https://bsonspec.org/spec.html.
Package bson2 implements encoding and decoding of BSON as defined by https://bsonspec.org/spec.html.
ferret/clientconn
Package clientconn provides client connection implementation.
Package clientconn provides client connection implementation.
ferret/clientconn/conninfo
Package conninfo provides access to connection-specific information.
Package conninfo provides access to connection-specific information.
ferret/clientconn/connmetrics
Package connmetrics provides listener and connection metrics.
Package connmetrics provides listener and connection metrics.
ferret/clientconn/cursor
Package cursor provides access to cursor registry.
Package cursor provides access to cursor registry.
ferret/handler
Package handler provides a universal handler implementation for all backends.
Package handler provides a universal handler implementation for all backends.
ferret/handler/common
Package common contains code used to be shared by different handlers.
Package common contains code used to be shared by different handlers.
ferret/handler/common/aggregations
Package aggregations provides aggregation pipelines.
Package aggregations provides aggregation pipelines.
ferret/handler/common/aggregations/operators
Package operators provides aggregation operators.
Package operators provides aggregation operators.
ferret/handler/common/aggregations/operators/accumulators
Package accumulators provides aggregation accumulator operators.
Package accumulators provides aggregation accumulator operators.
ferret/handler/common/aggregations/stages
Package stages provides aggregation stages.
Package stages provides aggregation stages.
ferret/handler/common/aggregations/stages/projection
Package projection provides projection for aggregations.
Package projection provides projection for aggregations.
ferret/handler/commonpath
Package commonpath contains functions used for path.
Package commonpath contains functions used for path.
ferret/handler/handlererrors
Package handlererrors provides handlers errors.
Package handlererrors provides handlers errors.
ferret/handler/handlerparams
Package handlerparams provides functions for parsing handlers parameters.
Package handlerparams provides functions for parsing handlers parameters.
ferret/handler/proxy
Package proxy sends requests to another wire protocol compatible service.
Package proxy sends requests to another wire protocol compatible service.
ferret/handler/registry
Package registry provides a registry of handlers.
Package registry provides a registry of handlers.
ferret/handler/sjson
Package sjson provides converters from/to jsonb with some extensions for built-in and `types` types.
Package sjson provides converters from/to jsonb with some extensions for built-in and `types` types.
ferret/types
Package types provides Go types matching BSON types that don't have built-in Go equivalents.
Package types provides Go types matching BSON types that don't have built-in Go equivalents.
ferret/types/fjson
Package fjson provides converters to FJSON (JSON with some extensions) for built-in and `types` types.
Package fjson provides converters to FJSON (JSON with some extensions) for built-in and `types` types.
ferret/util/ctxutil
Package ctxutil provides context helpers.
Package ctxutil provides context helpers.
ferret/util/debug
Package debug provides debug facilities.
Package debug provides debug facilities.
ferret/util/debugbuild
Package debugbuild provides information about whatever this is a debug build or not.
Package debugbuild provides information about whatever this is a debug build or not.
ferret/util/fsql
Package fsql provides database/sql utilities.
Package fsql provides database/sql utilities.
ferret/util/hex
Package hex provides helpers for working with hex dumps.
Package hex provides helpers for working with hex dumps.
ferret/util/iterator
Package iterator describes a generic Iterator interface and related utilities.
Package iterator describes a generic Iterator interface and related utilities.
ferret/util/iterator/testiterator
Package testiterator provides a helper for checking iterator implementations.
Package testiterator provides a helper for checking iterator implementations.
ferret/util/lazyerrors
Package lazyerrors provides error wrapping with file location.
Package lazyerrors provides error wrapping with file location.
ferret/util/logging
Package logging provides logging helpers.
Package logging provides logging helpers.
ferret/util/must
Package must provides helper functions that panic on error.
Package must provides helper functions that panic on error.
ferret/util/observability
Package observability provides abstractions for tracing, metrics, etc.
Package observability provides abstractions for tracing, metrics, etc.
ferret/util/password
Package password provides utilities for password hashing and verification.
Package password provides utilities for password hashing and verification.
ferret/util/resource
Package resource provides utilities for tracking resource lifetimes.
Package resource provides utilities for tracking resource lifetimes.
ferret/util/state
Package state stores FerretDB process state.
Package state stores FerretDB process state.
ferret/util/telemetry
Package telemetry provides basic telemetry facilities.
Package telemetry provides basic telemetry facilities.
ferret/util/testutil
Package testutil provides testing helpers.
Package testutil provides testing helpers.
ferret/util/testutil/testfail
Package testfail provides testing helpers for expected tests failures.
Package testfail provides testing helpers for expected tests failures.
ferret/util/testutil/teststress
Package teststress provides a helper for stress testing.
Package teststress provides a helper for stress testing.
ferret/util/testutil/testtb
Package testtb provides a common testing interface.
Package testtb provides a common testing interface.
ferret/util/tlsutil
Package tlsutil provides TLS utilities.
Package tlsutil provides TLS utilities.
ferret/wire
Package wire provides wire protocol implementation.
Package wire provides wire protocol implementation.
Package update is the main package for go-update-mongo
Package update is the main package for go-update-mongo

Jump to

Keyboard shortcuts

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