Methods
-
$accumulator(nodes, accumulator)
-
Go down the property tree of the collection
Parameters:
Name Type Description nodes
Array.<String> A variable of nodes to traverse down the json tree
accumulator
function Returns:
- Type
- jsonOdm.Query
-
$add(branch1, branch2)
-
Performs an arithmetic addition on two or more field values
Parameters:
Name Type Description branch1
jsonOdm.Query | Number branch2
jsonOdm.Query | Number Returns:
jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$add( $query.$branch("firstValue"), $query.$subtract( $query.$branch("lastValue"), $query.$branch(["otherValues","firstValue"]) ) ).$eq(12).$all();
-
$aggregateCollection(afterValidation [, beforeCollect] [, aggregation])
-
Helper method for aggregation methods
Parameters:
Name Type Argument Description afterValidation
Array.<function()> | function Push into the query queue after all commands have been executed. Returning false will result in a skip of this value
beforeCollect
Array.<function()> | function <optional>
Push into the before collect queue to change or replace the collection element
aggregation
Array.<function()> | function <optional>
If the result of the whole aggregation changes, i.e. for searching, or ordering
Returns:
- Type
- jsonOdm.Query
-
$all()
-
Returns a collection containing all matching elements
Returns:
- Type
- jsonOdm.Collection
Example
var collection = new jsonOdm.Collection("myCollection"); collection.$query() .$branch("id").$eq(2,9) .$all();
-
$and(queries)
-
Compares sub query results using the boolean and
Parameters:
Name Type Argument Description queries
jsonOdm.Query <repeatable>
A finite number of operators
Returns:
- Type
- jsonOdm.Query
-
$avg(branch)
-
Performs the accumulation average of a field. It's integrated to be used with $group. May as well be used as stand alone.
Parameters:
Name Type Argument Description branch
String <repeatable>
Internally calls the $branch method to receive the field values
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); $query.$avg("daysOff").$all(); console.log($query.$$accumulation);
-
$branch(node)
-
Go down the property tree of the collection
Parameters:
Name Type Argument Description node
String <repeatable>
A variable amount of nodes to traverse down the document tree
Returns:
- Type
- jsonOdm.Query
-
$count()
-
Counts the grouped elements
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$count(); $query.$count("daysOff").$all(); expect(collection.length).toBe($query.$$accumulation);
-
$delete()
-
Returns a collection containing all matching elements
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); collection.$query() .$branch("id").$gt(500) .$delete();
-
$divide(branch)
-
Performs an arithmetic divition on two or more field values
Parameters:
Name Type Description branch
jsonOdm.Query | Number Returns:
jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$divide( $query.$branch("firstValue"), $query.$add( $query.$branch("lastValue"), $query.$branch(["otherValues","firstValue"]) ) ).$eq(12).$all();
-
$eq(comparable)
-
Compares the current sub collection value with the comparable like this $eq('1','2','4') so 1 or 2 or 4 are valid fields
Parameters:
Name Type Argument Description comparable
* <repeatable>
Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$exists()
-
Compares the current sub collection value to not be undefined
Returns:
- Type
- jsonOdm.Query
-
$first()
-
Short hand version for $all(true)
Returns:
- Type
- jsonOdm.Collection
-
$geoIntersects(geometry)
-
Checks whether the current field geometry intersects the given geometry object
Warning: The coordinate reference system is WGS 84witch uses the coordinate order [longitude,latitude]!
The method automatically transforms arrays into the assumed GeoJSON definitions where:
[10,10] transforms into a jsonOdm.Geo.Point
[[10,10],[10,12],...] transforms into a jsonOdm.Geo.LineString
[[[10,10],[10,12],...],...] transforms into a jsonOdm.Geo.Polygon
[[[[10,10],[10,12],...],...],...] transforms into a jsonOdm.Geo.MultiPolygon
or simply use a GeoJSON object definition from jsonOdm.GeoParameters:
Name Type Description geometry
Array | jsonOdm.Geo.BoundaryBox | jsonOdm.Geo.Point | jsonOdm.Geo.MultiPoint | jsonOdm.Geo.LineString | jsonOdm.Geo.MultiLineString | jsonOdm.Geo.Polygon | jsonOdm.Geo.MultiPolygon | jsonOdm.Geo.GeometryCollection Returns:
- Type
- jsonOdm.Query
Example
{ "geo":[ { "type": "Feature", "properties": {...}, "geometry": { "type": "Polygon", "coordinates": [ ... ] } }, { "type": "Feature", "properties": {...}, "geometry": { "type": "Polygon", "coordinates": [ ... ] } }, ... ] } var collection = new jsonOdm.Collection("geo"), q = collection.$query().$branch("geometry").$geoIntersects(new jsonOdm.Geo.BoundaryBox([129.049317,-31.434555,139.464356,-19.068644])); //found geometries geometries = q.$all();
-
$geoWithin(geometry)
-
Checks whether the current field geometry is within the given geometry object
Warning: The coordinate reference system is WGS 84witch uses the coordinate order [longitude,latitude]!
The method automatically transforms arrays into the assumed GeoJSON definitions where:
[10,10] transforms into a jsonOdm.Geo.Point
[[10,10],[10,12],...] transforms into a jsonOdm.Geo.LineString
[[[10,10],[10,12],...],...] transforms into a jsonOdm.Geo.Polygon
[[[[10,10],[10,12],...],...],...] transforms into a jsonOdm.Geo.MultiPolygon
or simply use a GeoJSON object definition from jsonOdm.GeoParameters:
Name Type Description geometry
Array | jsonOdm.Geo.BoundaryBox | jsonOdm.Geo.Point | jsonOdm.Geo.MultiPoint | jsonOdm.Geo.LineString | jsonOdm.Geo.MultiLineString | jsonOdm.Geo.Polygon | jsonOdm.Geo.MultiPolygon | jsonOdm.Geo.GeometryCollection Returns:
- Type
- jsonOdm.Query
Example
{ "geo":[ { "type": "Feature", "properties": {...}, "geometry": { "type": "Polygon", "coordinates": [ ... ] } }, { "type": "Feature", "properties": {...}, "geometry": { "type": "Polygon", "coordinates": [ ... ] } }, ... ] } var collection = new jsonOdm.Collection("geo"), q = collection.$query().$branch("geometry").$geoWithin(new jsonOdm.Geo.BoundaryBox([129.049317,-31.434555,139.464356,-19.068644])); //found geometries geometries = q.$all();
-
$group()
-
Groups all elements of a collection by a given grouping schema
Parameters:
Type Argument Description jsonOdm.Query <repeatable>
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); var groupedResult = $query.$and($query.$branch("age").$gt(21),$query.$branch("age").$lt(50)) // query before grouping .$group( "salaryRate", // as used with $branch ["salaryGroup","name"], // as used with $branch // A projection object defining the accumulation { missingDays:$query.$sum("daysAtHome"), holidayDays:$query.$sum("daysOnHoliday"), averageMissingDays:$query.$avg("daysAtHome"), averageHolidayDays:$query.$avg("daysOnHoliday"), count:$query.$count() } ).$all(); // RESULT COULD BE // [ // {"salaryRate":3300,"salaryGroup":{"name":"Developer"},"missingDays":22,"holidayDays":144,"averageMissingDays":11,"averageHolidayDays":72,"count":2}, // {"salaryRate":2800,"salaryGroup":{"name":"Tester"} ,"missingDays":10,"holidayDays":66 ,"averageMissingDays":5, "averageHolidayDays":33,"count":2}, // {"salaryRate":4800,"salaryGroup":{"name":"Boss"} ,"missingDays":12,"holidayDays":33 ,"averageMissingDays":12,"averageHolidayDays":33,"count":1} // ]
-
$gt(comparable)
-
Compares the current sub collection value with the comparable like this $gt('1') field values greater then 1 are valid
Parameters:
Name Type Description comparable
* Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$gte(comparable)
-
Compares the current sub collection value with the comparable like this $gte('1') field values greater then or equal to 1 are valid
Parameters:
Name Type Description comparable
* Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$in(comparable)
-
Compares the current sub collection value with the comparable like this $in(['1','2','4']) so 1 or 2 or 4 are valid fields
Parameters:
Name Type Description comparable
Array Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$isNull()
-
Compares the current sub collection value to be null or undefined
Returns:
- Type
- jsonOdm.Query
-
$lt(comparable)
-
Compares the current sub collection value with the comparable like this $lt('1') field values less then 1 are valid
Parameters:
Name Type Description comparable
* Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$lte(comparable)
-
Compares the current sub collection value with the comparable like this $lte('1') field values less then or equal to 1 are valid
Parameters:
Name Type Description comparable
* Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$max(branch)
-
Performs the accumulation max of a field. It's integrated to be used with $group. May as well be used as stand alone.
Parameters:
Name Type Argument Description branch
String <repeatable>
Internally calls the $branch method to receive the field values
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); $query.$max("daysOff").$all(); console.log($query.$$accumulation);
-
$min(branch)
-
Performs the accumulation min of a field. It's integrated to be used with $group. May as well be used as stand alone.
Parameters:
Name Type Argument Description branch
String <repeatable>
Internally calls the $branch method to receive the field values
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); $query.$max("daysOff").$all(); console.log($query.$$accumulation);
-
$mod()
-
Compares the given reminder against the selected field value modulo the given divisor
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); collection.$query() // get every fourth element, so elements with id 4,8,12,... when starting with id 1 .$branch("id").$mod(4,0) .$all();
-
$modifyField()
-
Modify fields before validation
Returns:
- Type
- jsonOdm.Query
-
$modulo(branch, module)
-
Performs an arithmetic modulo on two or more field values
Parameters:
Name Type Description branch
jsonOdm.Query | Number module
jsonOdm.Query | Number Returns:
jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$modulo( $query.$branch("firstValue"), $query.$add( $query.$branch("lastValue"), $query.$branch(["otherValues","firstValue"]) ) ).$eq(12).$all();
-
$multiply(branch)
-
Performs an arithmetic multiplication on two or more field values
Parameters:
Name Type Description branch
jsonOdm.Query | Number Returns:
jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$multiply( $query.$branch("firstValue"), $query.$add( $query.$branch("lastValue"), $query.$branch(["otherValues","firstValue"]) ) ).$eq(12).$all();
-
$nand(queries)
-
Compares sub query results using the boolean nand
Parameters:
Name Type Argument Description queries
jsonOdm.Query <repeatable>
A finite number of operators
Returns:
- Type
- jsonOdm.Query
-
$ne(comparable)
-
Compares the current sub collection value with the comparable like this $ne('1','2','4') so 1 or 2 or 4 are not valid fields
Parameters:
Name Type Argument Description comparable
* <repeatable>
Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$nin(comparable)
-
Compares the current sub collection value with the comparable like this $nin(['1','2','4']) so 1 or 2 or 4 are not valid fields
Parameters:
Name Type Description comparable
Array Values to compare the current field with
Returns:
- Type
- jsonOdm.Query
-
$nor(queries)
-
Compares sub query results using the boolean nor
Parameters:
Name Type Argument Description queries
jsonOdm.Query <repeatable>
A finite number of operators
Returns:
- Type
- jsonOdm.Query
-
$not(queries)
-
An alisa for $nand
Parameters:
Name Type Argument Description queries
jsonOdm.Query <repeatable>
A finite number of operators
- See:
-
- jsonOdm.Query.$nand
Returns:
- Type
- jsonOdm.Query
-
$or(queries)
-
Compares sub query results using the boolean or
Parameters:
Name Type Argument Description queries
jsonOdm.Query <repeatable>
A finite number of operators
Returns:
- Type
- jsonOdm.Query
-
$project(projection)
-
Projects all elements of the collection into a given schema
Parameters:
Name Type Description projection
* The projection definition with nested definitions
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myBooks"); var $query = collection.$query() .$branch("id").$gt(12) // query before project .$project({ title: 1, isbn: { prefix: $query.$branch("isbn").$subString(0,3), group: $query.$branch("isbn").$subString(3,2), publisher: $query.$branch("isbn").$subString(5,4), title: $query.$branch("isbn").$subString(9,3), checkDigit: $query.$branch("isbn").$subString(12,1) }, lastName: function(element){return element.author.last}, // functions can be used as well copiesSold: $query.$branch("copies") }); var collectionResult = $query.$all();
-
$push()
-
adds the grouped elements to result set
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); $query.$push("daysOff").$all() expect(collection.length).toBe($query.$$accumulation.length);
-
$queryOperator(queries, operator)
-
Test a collection or collection field against one or more values
Parameters:
Name Type Description queries
Array.<jsonOdm.Query> A finite number of operators
operator
function the test function to evaluate the values
Returns:
- Type
- jsonOdm.Query
-
$regex(regex [, options])
-
Tests a selected field against the regular expression
Parameters:
Name Type Argument Description regex
RegExp | string The regular expression to test against
options
string <optional>
The regular expression options, i.e. "i" for case insensitivity
Returns:
- Type
- jsonOdm.Query
Examples
var collection = new jsonOdm.Collection("myCollection"); collection.$query() // gets all elements with a name of "Richard","RiChI","RichI","richard",... .$branch("name").$regex(/rich(i|ard)/i) .$all();
var collection = new jsonOdm.Collection("myCollection"); collection.$query() // gets all elements with a name of "Richard","RiChI","RichI","richard",... .$branch("name").$regex("rich(i|ard)","i") .$all();
-
$result( [start] [, length])
-
Returns a collection containing all matching elements within the given range
Parameters:
Name Type Argument Description start
int <optional>
return a subset starting at n; default = 0
length
int <optional>
return a subset with the length n; default = collection length
Returns:
- Type
- *
Example
var collection = new jsonOdm.Collection("myCollection"); collection.$query() .$branch("id").$eq(2,9) .$result(1,3);
-
$subtract(branch)
-
Performs an arithmetic subtraction on two or more field values
Parameters:
Name Type Description branch
jsonOdm.Query | Number Returns:
jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$subtract( $query.$branch("firstValue"), $query.$add( $query.$branch("lastValue"), $query.$branch(["otherValues","firstValue"]) ) ).$eq(12).$all();
-
$sum(branch)
-
Performs the accumulation sum of a field. It's integrated to be used with $group. May as well be used as stand alone.
Parameters:
Name Type Argument Description branch
String <repeatable>
Internally calls the $branch method to receive the field values
Returns:
- Type
- jsonOdm.Query
Example
// SHOULD BE USED WITH $group var collection = new jsonOdm.Collection("employees"); var $query = collection.$query(); $query.$sum("daysOff").$all(); console.log($query.$$accumulation);
-
$testCollection(comparables, collectionTest)
-
Test a collection or collection field against one or more values
Parameters:
Name Type Description comparables
* An array of values to test again
collectionTest
function the test function to evaluate the values
Returns:
- Type
- jsonOdm.Query
-
$text(text)
-
Performs a text search on a given collection with the same notation used by mongodb
In contrast to mongodb this method does not implement stop words elimination or word stamming at the momentParameters:
Name Type Description text
String Returns:
- Type
- jsonOdm.Query
Example
collection.$query() // Must find "Ralf Tomson" and ("Jack" or "Josh") and not("Matteo") .$branch("name").$text("Jack Josh \"Ralf Tomson\" -Matteo") .$all();
-
$type(type)
-
Compares the current sub collection against the given types using the binary of and the JavaScript typeof Supported (case insensitive) types are: number, string, undefined, object, array and RegExp, ArrayBuffer, null, boolean plus all other [object *] types
Parameters:
Name Type Argument Description type
string <repeatable>
A list of allowed types for the selected field
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); collection.$query() // id is string or number and not undefined or null .$branch("id").$type("string","number") .$all();
-
$where(evaluation)
-
Performs a query selection by a self defined function of function body string. The function context (this) will be the current collection or a value selected by $branch.
Parameters:
Name Type Description evaluation
string | function Returns:
- Type
- jsonOdm.Query
Example
// !!!! NOT SUPPORTED ANYMORE !!!! using a string to find Harry collection.$query().$where("return this.name == 'Harry';").$first(); // using a function to find Harry collection.$query().$where(function(){return this.name == 'Harry';}).$first(); // using $where after selecting a branch collection.$query().$('name').$where(function(){return this == 'Harry';}).$first();
-
StringPrototype( [args])
-
A generation for all native String.prototype methods to make them available via $modifyField
Supported Methods are: "charAt", "charCodeAt", "concat", "fromCharCode", "indexOf", "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", "split", "substr", "substring", "toLocaleLowerCase", "toLocaleUpperCase", "toLowerCase", "toUpperCase", "trim", "valueOf"Parameters:
Name Type Argument Description args
* <optional>
The string methods parameter
Returns:
- Type
- jsonOdm.Query
Example
var collection = new jsonOdm.Collection("myCollection"); var $query = collection.$query(); $query.$branch("explosionBy").$trim().$substr(0,3).$toUpperCase().$eq("TNT").$all();