Match MongoDB queries, apply updates and test aggregation pipelines on local documents.

Additional Documentation Pages

Modules

Sorting

Generate sorter Functions for ordering documents and leaves.

| class Set

Collects a set of unique MongoDB documents.

Static Functions

, | Array | Array [ Array , ] aggregate ( ) {

Locally apply a MongoDB aggregation pipeline. Does not affect the input documents. Optionally returns the results of each individual stage as well as the final result.

Arguments

| Array [ Object , ] docs

An Array of documents to process.

| Array [ Object , ] pipeline

An Array of stage operator specifications used to select/modify the source documents.

optional
| Boolean keepStages

If true, the return value is an Array containing each Array of results produced by each stage. Otherwise the return value is the final result Array.

Returns

| Array | Array [ Array , ]

Either the final result set or an Array containing the result set of each stage.

, | Number getBSONType ( ) {

Return a numeric BSON type for a javascript object.

Arguments

| Object subject

The object to test for type.

optional
| Boolean simpleNums

In simpleNums mode, a Number is always of DOUBLE type. Otherwise it will be evaluated as potentially an integer.

Returns

| Number

Returns one of the following values:

  • 0 - unknown type
  • 1 - double
  • 2 - string
  • 3 - object
  • 4 - array
  • 5 - buffer
  • 6 - undefined
  • 7 - ObjectID
  • 8 - boolean
  • 9 - date
  • 10 - null
  • 11 - regexp
  • 13 - function
  • 16 - integer
  • 18 - long
, | Boolean matchQuery (
, [ root ]
) {

Determine whether a query selects a given document.

Arguments

| Object doc

The document to be examined.

| Object query

The query to test against the document.

optional
| String root

Indicates an offset document position. Permits testing a full query against a subdocument.

Returns

merge (
, [ query ]
) {

Recursively merge the result of a query into a local document, overwriting the document with fresh query results. A projection specification may be provided to intelligently merge projected fields.

Arguments

| Object source

Freshly queried state information.

| Object target

The target document to recursively merge into.

optional
| Object query

If the projection uses the positional operator, the query may be included to define its position.

optional
| Object projection

If a projection is provided, the merge will honor any special projection options.

project (
, [ query ]
) {

Generate a document with another document using a MongoDB projection specification.

Arguments

| Object document

The source document to project.

optional
| Object query

If the projection uses the positional operator, provide a query to define it.

| Object projection

The projection specification used to generate a new document.

resolveDollar ( ) {

Determine the numeric index, if any, of a value matching the positional operator. The prefix path where the positional operator was found is required, e.g. comments.$.author uses the path comments.

Both path and pathstr are required (not generated) because if you are calling resolveDollar you probably have or need both of these anyway.

Arguments

| Object target

The outer document to search. Must have the same root as the path and pathstr arguments.

| Object query

The query object used to generate the positional operator.

| Array path

The prefix path where the positional operator was found, as an Array of keys.

| String pathstr

The prefix path where the positional operator was found, as a dot-delimited String.

update (
, [ query ]
) {

Apply a MongoDB update operation in place.

Arguments

optional
| Object query

If the update uses the positional operator, provide a query to define it.

| Object target

The document to update. This document will be modified.

| Object change

The update specification to apply.