Skip to content

zaporter/go-update-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

UpdateDocument is tested against a locally running monogo 6.0 docker. The test connects to mongo, inserts the test object, runs updateOne() on it, and then ensures that it is exactly equal to the document produced by UpdateDocument() (ordering of keys and all)

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

About

In-memory mongo update operations on single documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages