jsonpatchtomongo

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 7 Imported by: 0

README

JSON Patches to Mongo

This utility converts JSON patches to MongoDB update queries.

Using the package

To install the package run

go get github.com/ZaninAndrea/json-patch-to-mongo

Then you can use the utility simply by passing the JSON Patches as []byte to the ParsePatches function

patches := []byte(`[
    { "op": "add", "path": "/hello/0/hi/5", "value": 1 },
    { "op": "add", "path": "/hello/0/hi/5", "value": 2 },
    { "op": "replace", "path": "/world", "value": {"foo":"bar"} }
]`)
updateQuery, err := ParsePatches(patches)

Credits

This is a Go port of the JavaScript library jsonpatch-to-mongodb.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePatches

func ParsePatches(patches []byte) (bson.M, bool, error)

ParsePatches accepts the JSON Patches as []byte and returns the equivalent MongoDB update query as bson.M

func ParsePatchesWithPrefix added in v1.0.2

func ParsePatchesWithPrefix(patches []byte, prefixPath string) (bson.M, bool, error)

ParsePatchesWithPrefix accepts the JSON Patches as []byte and returns the equivalent MongoDB update query as bson.M, all the paths are prepended with the prefix passed

Types

This section is empty.

Jump to

Keyboard shortcuts

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