Skip to content

Commit f5d216d

Browse files
committed
feat: add or clause to ObjectId
1 parent ce54e35 commit f5d216d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/database",
3-
"version": "5.16.0",
3+
"version": "5.17.0",
44
"description": "The Athenna database handler for SQL/NoSQL.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/database/drivers/MongoDriver.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818

1919
import { debug } from '#src/debug'
2020
import { Log } from '@athenna/logger'
21+
import { ObjectId } from '#src/helpers/ObjectId'
2122
import { Driver } from '#src/database/drivers/Driver'
2223
import { ModelSchema } from '#src/models/schemas/ModelSchema'
2324
import { Transaction } from '#src/database/transactions/Transaction'
@@ -28,7 +29,6 @@ import { WrongMethodException } from '#src/exceptions/WrongMethodException'
2829
import { MONGO_OPERATIONS_DICTIONARY } from '#src/constants/MongoOperationsDictionary'
2930
import { NotConnectedDatabaseException } from '#src/exceptions/NotConnectedDatabaseException'
3031
import { NotImplementedMethodException } from '#src/exceptions/NotImplementedMethodException'
31-
import { ObjectId } from '#src/helpers/ObjectId'
3232

3333
export class MongoDriver extends Driver<Connection, Collection> {
3434
public primaryKey = '_id'
@@ -1214,7 +1214,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
12141214
public whereIn(column: string, values: any[]) {
12151215
values = values.flatMap(value => {
12161216
if (ObjectId.isValidStringOrObject(value)) {
1217-
return [value, new ObjectId(value)]
1217+
return [String(value), new ObjectId(value)]
12181218
}
12191219

12201220
return [value]
@@ -1231,7 +1231,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
12311231
public whereNotIn(column: string, values: any[]) {
12321232
values = values.flatMap(value => {
12331233
if (ObjectId.isValidStringOrObject(value)) {
1234-
return [value, new ObjectId(value)]
1234+
return [String(value), new ObjectId(value)]
12351235
}
12361236

12371237
return [value]
@@ -1362,7 +1362,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
13621362
public orWhereIn(column: string, values: any[]) {
13631363
values = values.flatMap(value => {
13641364
if (ObjectId.isValidStringOrObject(value)) {
1365-
return [value, new ObjectId(value)]
1365+
return [String(value), new ObjectId(value)]
13661366
}
13671367

13681368
return [value]
@@ -1379,7 +1379,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
13791379
public orWhereNotIn(column: string, values: any[]) {
13801380
values = values.flatMap(value => {
13811381
if (ObjectId.isValidStringOrObject(value)) {
1382-
return [value, new ObjectId(value)]
1382+
return [String(value), new ObjectId(value)]
13831383
}
13841384

13851385
return [value]
@@ -1548,7 +1548,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
15481548
const objectId = condition[key]
15491549

15501550
condition.$or.push(
1551-
{ [key]: objectId },
1551+
{ [key]: String(objectId) },
15521552
{ [key]: new ObjectId(objectId) }
15531553
)
15541554

@@ -1579,7 +1579,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
15791579
const objectId = condition[key]
15801580

15811581
condition.$or.push(
1582-
{ [key]: objectId },
1582+
{ [key]: String(objectId) },
15831583
{ [key]: new ObjectId(objectId) }
15841584
)
15851585

0 commit comments

Comments
 (0)