Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation cursor empty #83

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"homepage": "https://github.com/neo9/n9-mongodb-client#readme",
"engines": {
"node": ">= 16.20"
"node": ">= 18"
},
"dependencies": {
"@neo9/n9-node-log": "^5.0.0-rc.7",
Expand All @@ -51,24 +51,24 @@
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21",
"mingo": "^6.4.7",
"mongodb": "~6.1.0",
"mongodb": "~6.2.0",
"promise-pool-executor": "^1.1.1"
},
"peerDependencies": {
"class-transformer": "0.4.0"
"class-transformer": "0.5.1"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@commitlint/cli": "^17.7.2",
"@neo9/n9-coding-style": "^5.1.2",
"@commitlint/cli": "^18.2.0",
"@neo9/n9-coding-style": "^6.0.0-rc.3",
"@release-it/conventional-changelog": "^7.0.2",
"@tsconfig/node16": "^16.1.1",
"@types/deep-diff": "^1.0.3",
"@types/lodash": "^4.14.199",
"@types/node": "^16.18.58",
"@types/std-mocks": "^1.0.2",
"ava": "^5.3.1",
"class-transformer": "0.4.0",
"class-transformer": "0.5.1",
"husky": "^4.3.8",
"mongodb-memory-server": "^9.0.1",
"nyc": "^15.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { N9Log } from '@neo9/n9-node-log';
import { N9Error } from '@neo9/n9-node-utils';
import * as fastDeepEqual from 'fast-deep-equal/es6';
import * as FastDeepEqual from 'fast-deep-equal/es6';
import * as _ from 'lodash';
import * as mingo from 'mingo';
import {
Expand Down Expand Up @@ -1860,7 +1860,7 @@ export class N9MongoDBClient<U extends BaseMongoObject, L extends BaseMongoObjec
newEntityFiltered = newEntityOmitted;
}

return fastDeepEqual(snapshotFiltered, newEntityFiltered);
return FastDeepEqual(snapshotFiltered, newEntityFiltered);
}

// Method is not static to use U and L
Expand Down
3 changes: 2 additions & 1 deletion src/cursors/n9-aggregation-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class N9AggregationCursor<E> extends N9AbstractCursor<E> {
},
])
.toArray();
return countResult[0].n;
if (countResult.length > 0) return countResult[0].n;
return 0; // empty cursor
}
}
6 changes: 3 additions & 3 deletions src/lodash-replacer.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
import * as v8 from 'v8';
import * as V8 from 'v8';

export class LodashReplacerUtils {
public static IS_NIL(value: any): value is null | undefined {
Expand Down Expand Up @@ -64,9 +64,9 @@ export class LodashReplacerUtils {
}

public static CLONE_DEEP<T>(value: T): T {
if (v8.deserialize) {
if (V8.deserialize) {
// Added in Node 11
return v8.deserialize(v8.serialize(value));
return V8.deserialize(V8.serialize(value));
}
return _.cloneDeep(value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mongo-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { N9Log } from '@neo9/n9-node-log';
import { N9Error } from '@neo9/n9-node-utils';
import { ClassTransformOptions, plainToClass } from 'class-transformer';
import { ClassTransformOptions, plainToInstance } from 'class-transformer';
import * as _ from 'lodash';
import * as mongodb from 'mongodb';
import { ListCollectionsOptions } from 'mongodb';
Expand Down Expand Up @@ -210,7 +210,7 @@ export class MongoUtils {

const newPlain = MongoUtils.MAP_OBJECT_ID_TO_STRING_HEX(plain);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return plainToClass(cls, newPlain, options) as T;
return plainToInstance(cls, newPlain, options) as T;
}

public static REMOVE_SPECIAL_CHARACTERS_IN_KEYS(obj: any): any {
Expand Down
7 changes: 7 additions & 0 deletions test/aggregation-cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ test('[Cursor] Check count function', async (t: ExecutionContext<ContextContent>
t.context.mongoClient.newAggregationBuilder().match(filterQuery).group({ _id: 1 }),
);
t.is(await cursor.count(), 1, 'cursor only contains the group result');

cursor = t.context.mongoClient.aggregateWithBuilder<SampleType>(
t.context.mongoClient
.newAggregationBuilder()
.match({ $and: [{ _id: { $eq: '1' } }, { _id: { $ne: '1' } }] }),
);
t.is(await cursor.count(), 0, 'empty cursor count is 0');
});

test('[Cursor] Check cursor clone function', async (t: ExecutionContext<ContextContent>) => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function init(initOptions?: InitOptions): void {
// no classic mongodb available, so use one in memory
mongod = await MongoMemoryServer.create({
binary: {
version: '6.0.4',
version: '6.0.9',
},
});

Expand Down
6 changes: 3 additions & 3 deletions test/locks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ test('[LOCKS] Try ensuring index with wrong collection name', async (t: Executio
result = await lock.ensureIndexes();
},
{
message: "Collection names must not contain '$'",
message: 'Invalid collection name: $collection-name',
},
);
t.truthy(!result, "The lock can't be ensured due to invalid collection name (contains $)");
Expand All @@ -534,7 +534,7 @@ test('[LOCKS] Try acquiring lock with wrong collection name', async (t: Executio
code = await lock.acquire();
},
{
message: "Collection names must not contain '$'",
message: 'Invalid collection name: $collection-name',
},
);
t.truthy(!code, "The lock can't be acquired due to invalid collection name (contains $)");
Expand Down Expand Up @@ -569,7 +569,7 @@ test('[LOCKS] Try releasing lock with wrong collection name', async (t: Executio
ok = await lock.release('a-fake-lock-id');
},
{
message: "Collection names must not contain '$'",
message: 'Invalid collection name: $collection-name',
},
);
t.truthy(!ok, "The lock can't be released due to invalid collection name (contains $)");
Expand Down
Loading