update

package
v1.0.0-beta.122 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldOPType

type FieldOPType string

FieldOPType is the field operator passed in the Update API.

const (
	Set       FieldOPType = "$set"
	UnSet     FieldOPType = "$unset"
	Increment FieldOPType = "$increment"
	Decrement FieldOPType = "$decrement"
	Multiply  FieldOPType = "$multiply"
	Divide    FieldOPType = "$divide"
	Push      FieldOPType = "$push"
)

type FieldOperator

type FieldOperator struct {
	Op    FieldOPType
	Input jsoniter.RawMessage
}

A FieldOperator can be of the following type: { "$set": { <field1>: <value1>, ... } } { "$increment": { <field1>: <incrementBy> } } { "$decrement": { <field1>: <decrementBy> } } { "$multiply": { <field1>: <multiplyBy> } } { "$divide": { <field1>: <divideBy> } } { "$unset": ["d"] }. { "$push": { <field1>: <value1>, ... } }.

func NewFieldOperator

func NewFieldOperator(op FieldOPType, val jsoniter.RawMessage) *FieldOperator

NewFieldOperator returns a FieldOperator.

type FieldOperatorFactory

type FieldOperatorFactory struct {
	FieldOperators map[string]*FieldOperator
}

The FieldOperatorFactory has all the field operators passed in the Update API request. The factory implements a MergeAndGet method to convert the input to the output JSON that needs to be persisted in the database.

func BuildFieldOperators

func BuildFieldOperators(reqFields []byte) (*FieldOperatorFactory, error)

BuildFieldOperators un-marshals request "fields" present in the Update API and returns a FieldOperatorFactory The FieldOperatorFactory has the logic to remove/merge the JSON passed in the input and the one present in the database.

func (*FieldOperatorFactory) MergeAndGet

func (factory *FieldOperatorFactory) MergeAndGet(existingDoc jsoniter.RawMessage, collection *schema.DefaultCollection) (jsoniter.RawMessage, []string, bool, error)

MergeAndGet method to converts the input to the output after applying all the operators. First "$set" operation is applied and then "$unset" which means if a field is present in both $set and $unset then it won't be stored in the resulting document.

Jump to

Keyboard shortcuts

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