Finding documents (persistent.findDocuments)
You can use persistent.findDocuments
to find documents based on a particular document definition.
For documents saved in V1 the function: persistent.findDocumentsV1
can be used.
Syntax
persistent.findDocuments(ddName, queryObject, queryOptions);
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
ddName | String or null |
Yes | The name of the document definition. If the value is null , BizzStream will use the name of the document from which the script was started. |
queryObject | object | Yes | The object with which you can specify the search criteria. This object has to be made in the Mongo query format |
queryOptions | Object | No | The options that can be used in the Mongo query |
Query options
Query Parameter | Type | Description |
---|---|---|
sort | number | Used for the soring order (default: natural order). This is an object that contains the fields and their sorting order. The value -1 represents a descending sorting order while the value 1 represents an ascending sorting order |
skip | number | Number of results to skip at the beginning. |
fields | number | Dictionary of fields to return or exclude. This is an object that contains the fields and an indication of whether the field is included (value 1) or excluded (value -1) |
limit | number | Maximum number of results to return. |
Return value
An array containing the documents. If no documents can be found, a null
value.
If the query object includes any undefined values or is entirely undefined, it will throw an error.
When a document is found it will return an object something like this:
[
{
_id: 'i8Dz0cKKp48mcW648ExZ',
status: 'ready',
accessGroups: [ [Object], [Object], [Object], [Object] ],
_documentDefinitionId: 'CghGFDo90qxqKaJI25owl',
_environmentId: 'maxedy_pizza',
picture: [ [Object] ],
externalId: 'external_i6Z3DzmccKKp4WExZ',
_createdByUserId: '2LhXDMnJ83wfGkXHe',
_lastModifiedOn: '2025-04-23T10:19:33.573Z',
_createdOn: '2023-06-23T09:44:35.853Z',
_lastModifiedByUserId: '1YNEXKYkPnqk52Fzf',
_hash: 'rqAZfgL8lePNqHTgdI2I70Lub5WoB50m5zj1FPOeviE='
}
]
Examples
The following method allows you to search for documents of the type project
for which the projectNr
field is equal to 12345
.
persistent.findDocuments('project', {"projectNr":"12345"});
console.log('Give me the documents with projectnumber 12345', projectNumber)