package
0.6.0
Repository: https://github.com/stevencyb/goquery.git
Documentation: pkg.go.dev

# README

Query for operational path

With "patch operations" patches can be specified in detail base on RFC6902 (test operation is not implemented - use RSQL Parser instead) There are five operations available:

OperationDescription
removeremove the value at the target location.
addadd a value or array to an array at the target location.
replacereplaces the value at the target location with a new value.
moveremoves the value at a specified location and adds it to the target location.
copycopies the value from a specified location to the target location.

This features are supported for MongoDB 4.2+.

Additionally, simple rules can be set:

PolicyDescription
DisallowPathPolicyspecifies a path that is not allowed.
DisallowOperationOnPathPolicydisallows specified operation on path.
ForceTypeOnPathPolicyforces the value of a specif path to be from given type.
ForceRegexMatchPolicyforces the value of a specif path to match expression.

How to

Basic usage

import (
  "github.com/StevenCyb/goquery/parser/mongo/patchoperation"

  "go.mongodb.org/mongo-driver/mongo/options"
)
// ...

  var operations []patchoperation.OperationSpec
  err = json.NewDecoder(req.Body).Decode(&operations)
  // ...

  parser := patchoperation.NewParser()
  query, err := parser.Parse(operations...)
  // ...

  result := collection.FindOneAndUpdate(ctx, filter, query, updateOptions)
  // ...

Policy usage

  parser := patchoperation.NewParser(
    DisallowPathPolicy{Details: "illegal ID modification", Path: "_id"},
    ForceTypeOnPathPolicy{Details: "age as number", Path: "user.age", Kind: reflect.Int64},
  ),

# Functions

NewParser creates a new parser.

# Constants

AddOperation add a value or array to an array at the target location.
CopyOperation copies the value from a specified location to the target location.
MoveOperation removes the value at a specified location and adds it to the target location.
RemoveOperation is an operation to remove the value at the target location.
ReplaceOperation replaces the value at the target location with a new value.

# Structs

DisallowOperationOnPathPolicy disallows specified operation on path.
DisallowPathPolicy specifies a path that is not allowed.
ForceRegexMatchPolicy forces the value of a specif path to match expression.
ForceTypeOnPathPolicy forces the value of a specif path to be from given type.
OperationSpec specify an path operation.
Parser that can parse patch operation to generate mongo queries.

# Interfaces

Policy specifies the interface for an policy.

# Type aliases

No description provided by the author
No description provided by the author