Skip to content

The cursor.forEach callback is called with "undefined" even if there are no results #683

@rensdewolf

Description

@rensdewolf

arangojs 7.0.1
arangodb 3.6.5
typescript 4.0.2

When running the following using a db instance:

const query = aql`FOR i IN [] RETURN i`;
const cursor = await db.query(query, { count: true });
console.log(cursor.count);
await cursor.forEach((value: any) => { console.log(value); });

The console output is:

0
undefined

It seems the forEach callback is called once although the count is 0. IMHO this should not happen and the console output should read 0 only. Note that in the previous version (6.x.x), the each callback was not called.

The forEach method of the ArrayCursor looks at this.hasMore || Boolean(this._batches.length) to execute the callback. The use of the non-null assertion operator on the value seems somewhat misleading as value returned is undefined. Not sure why the _batches.length equals 1...

Metadata

Metadata

Assignees

Labels

BugA code defect that needs to be fixed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions