mongofil

package module
v0.0.0-...-08cc741 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2016 License: MIT Imports: 4 Imported by: 0

README

GoDoc Build Status Coverage Status Go Report Card License

mongofil

Checking if JSON matches mongodb query and finding matched documents in JSON array. Project is on very early stage. Contributors welcome!

Roadmap:

  • Support for nested documents and arrays
  • Filter JSON array to only matched documents
  • Caching extracted values to use them in multiple operators
Implement query operators
Comparison
  • $eq Matches values that are equal to a specified value.
  • $gt Matches values that are greater than a specified value.
  • $gte Matches values that are greater than or equal to a specified value.
  • $lt Matches values that are less than a specified value.
  • $lte Matches values that are less than or equal to a specified value.
  • $ne Matches all values that are not equal to a specified value.
  • $in Matches any of the values specified in an array.
  • $nin Matches none of the values specified in an array.
Logical
  • $or Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
  • $and Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
  • $not Inverts the effect of a query expression and returns documents that do not match the query expression.
  • $nor Joins query clauses with a logical NOR returns all documents that fail to match both clauses.
Element
  • $exists Matches documents that have the specified field.
  • $type Selects documents if a field is of the specified type.
Evaluation
  • $mod Performs a modulo operation on the value of a field and selects documents with a specified result.
  • $regex Selects documents where values match a specified regular expression.
  • $text Performs text search.
  • $where Matches documents that satisfy a JavaScript expression.
Geospatial
  • $geoWithin Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.
  • $geoIntersects Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
  • $near Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near.
  • $nearSphere Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
Array
  • $all Matches arrays that contain all elements specified in the query.
  • $elemMatch Selects documents if element in the array field matches all the specified $elemMatch conditions.
  • $size Selects documents if the array field is a specified size.

Documentation

Index

Constants

View Source
const (
	NotExist = ValueType(iota)
	String
	Number
	Object
	Array
	Boolean
	Null
	Unknown

	RegExp = 10
)

Variables

View Source
var (
	ErrEmptyFieldName = errors.New("empty field name")
	ErrInMustBeArray  = errors.New("$in must points to array of interface{}")
	ErrAndMustBeArray = errors.New("$and must points to array of map[string]interface{}")
	ErrOrMustBeArray  = errors.New("$or must points to array of map[string]interface{}")
	ErrNorMustBeArray = errors.New("$nor must points to array of map[string]interface{}")
	ErrNotMustBeMap   = errors.New("$not must points to map[string]interface{}")
)

Errors

Functions

func Match

func Match(query map[string]interface{}, doc []byte) (bool, error)

Match returns true if JSON matched query returns error if query contains errors

Types

type Matcher

type Matcher interface {
	Match(doc []byte) bool
}

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a "compiled" query

func NewQuery

func NewQuery(query map[string]interface{}) (*Query, error)

NewQuery returns new compiled query

func (*Query) Match

func (q *Query) Match(doc []byte) bool

Match returns true if document matched compiled query

type ValueType

type ValueType int

ValueType is representation of data types available in valid JSON data.

Jump to

Keyboard shortcuts

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