Fix for $in on ObjectIds (#11014)
This commit is contained in:
parent
4788972362
commit
0ecda93ea9
|
@ -380,18 +380,26 @@ class MongoIntegration implements IntegrationBase {
|
|||
return this.client.connect()
|
||||
}
|
||||
|
||||
matchId(value?: string) {
|
||||
return value?.match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0]
|
||||
}
|
||||
|
||||
hasObjectId(value?: any): boolean {
|
||||
return (
|
||||
typeof value === "string" && value.toLowerCase().startsWith("objectid")
|
||||
)
|
||||
}
|
||||
|
||||
createObjectIds(json: any): object {
|
||||
const self = this
|
||||
|
||||
function interpolateObjectIds(json: any) {
|
||||
for (let field of Object.keys(json || {})) {
|
||||
if (json[field] instanceof Object) {
|
||||
json[field] = self.createObjectIds(json[field])
|
||||
}
|
||||
if (
|
||||
typeof json[field] === "string" &&
|
||||
json[field].toLowerCase().startsWith("objectid")
|
||||
) {
|
||||
const id = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0]
|
||||
if (self.hasObjectId(json[field])) {
|
||||
const id = self.matchId(json[field])
|
||||
if (id) {
|
||||
json[field] = ObjectId.createFromHexString(id)
|
||||
}
|
||||
|
@ -402,7 +410,14 @@ class MongoIntegration implements IntegrationBase {
|
|||
|
||||
if (Array.isArray(json)) {
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
json[i] = interpolateObjectIds(json[i])
|
||||
if (self.hasObjectId(json[i])) {
|
||||
const id = self.matchId(json[i])
|
||||
if (id) {
|
||||
json[i] = ObjectId.createFromHexString(id)
|
||||
}
|
||||
} else {
|
||||
json[i] = interpolateObjectIds(json[i])
|
||||
}
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue