Path

Paths are returned by collection.parsePath(path). They are used to make writing generic metadata-based code easier.

Path is also able to deal with denormalized paths as well.

See paths for more information.

static

decode(path: string): string

This decodes a MongoDB-safe path string into a regular path string.

encode(path: string): string

This encodes a regular path into a MongoDB-safe path string.

MongoDB does not support periods appearing inside key names inside objects stored in MongoDB. However, sometimes we need to store Tyranid metadata inside the database that uses Tyranid paths. This method encodes those values into something that MongoDB will store.

populateNameFor(name: string, denormal: boolean): string

This returns the name for the populated field the given path.

namepopulateNameFor(denormal: false)/u>populateNameFor(denormal: true)
'customer''customer$''customer_'
'customerId''customer''customer_'
resolve(collection: Collection,
parentPath?: Path | string,
path?: Path | string): Path | undefined

This resolves a new Path instance from a parent path and a child path.

If both the parent path and child path are missing, this will return undefined.

instance

$metaType: 'path'

This returns 'path'.

base: Collection | Path

This returns the object that this name path is relative to (usually a collection, but it could be relative to another name path).

detail: Field

This is a more detailed version of tail.

Often you are only interested in the end of the path which has the Type of the path you are working with.

This is a shortcut for skipArrays(this.pathFields[this.pathFields.length-1]).

If the path parent.children refers to a an array of string, the tail points at the array but detail points at the contents of the array -- i.e. the string field.

fields: Field[]

This array contains the Field for each step along the path. This is a parallel array to path.

get(obj: object): any

This walks the obj according to this path and returns the values at this path. (There can be multiple values if the path crosses any arrays. If so, this method will return duplicate values if values occur more than once. See Path.uniq().)

groupCount: number

This returns the number of path groups inside this path. Groups are created by using a '|' instead of a '.' as a separatror.

groupLabel(groupNumber: number): string

This returns the label for the given group. Groups are created by using a '|' instead of a '.' as a separatror.

groupRange(groupNumber: number): [number, number]

This returns the range of fields for the given group. Groups are created by using a '|' instead of a '.' as a separatror.

identifier: string

This returns a simple identifier for this field that does not have periods (.) in it.

This can be useful for some libraries which don't deal with with embedded periods like getFieldDecorator.

For example:

PathIdentifier
siblings._.namesiblings___name
name.firstname_first
ageage
isHistorical(): boolean

This returns true if this path represents a historical property.

label: string

This contains the full path label for this name path. This includes both the group and path portions.

For example, given a path of orders.location|city.name:

MethodLabel
groupLabel(0)Order Locations
pathLabelCity
labelOrder Location City
name: string

This contains the full, unparsed path that was passed into the constructor.

parsePath(path: string): Path

This returns a new Path relative to the current name path. Any objects passed into methods on this new Path like get, set, and so on must also be relative in the same way.

path: string[]

This contains the path split up into individual strings for steps on the path.

namepath(name)
'name'[ 'name' ]
'name.first'[ 'name', 'first' ]
'organization_.owner_.name.first'[ 'organization_', 'owner_', 'name', 'first' ]
pathLabel: string

This contains the full path label for this name path except for the group portion of this path (if any).

pathName(idx: integer): string

This returns a verbose description of the path at position idx along the path. This is useful for error messages in parsing.

projectify(projection: Mongo projection): void

This adds the current path to the given projection.

If this path refers to a computed field, then all of the fields needed to perform the computation will be added to the projection as well.

set(obj: object, value: any, opts: object): void

This walks the obj according to this path and sets the given value at that point in the path.

opts is as follows:

OptionTypeNotes
{
create:booleanIf true, set() will create any missing ancestor objects or arrays as needed..
ignore:booleanIf true, set() will silently fail if ancestor objects or arrays are missing..
}
spath: string

This contains the simplified path of this field.

Simplified paths remove the array contents reference and are useful when working with MongoDB projections. For example:

PathSimplified Path
siblings._.namesiblings.name
siblings.0.namesiblings.name
name.firstname.first
ageage

See Paths for more information.

spathArr: string

This contains the simplified path of this field that includes array indices.

Simplified paths remove the array contents reference and are useful when working with MongoDB projections. For example:

PathSimplified Path
siblings._.namesiblings.name
siblings.0.namesiblings.0.name
name.firstname.first
ageage

See Paths for more information.

tail: Field

This is a shortcut for this.pathFields[this.pathFields.length-1]. Often you are only interested in the end of the path which has the Type of the path you are working with.

This property is related to detail. If the path parent.children refers to a an array of string, the tail points at the array but detail points at the contents of the array -- i.e. the string field.

uniq(obj: object): any[]

This walks the obj according to this path and returns the uniq values at this path it finds. (There can be multiple values if the path crosses any arrays.)

walk(path?: Path | string): Path

This resolves a new Path instance that is relative to the current Path.