Merge pull request #7422 from Budibase/bug/sev3/mongodb-objectid-relationship

Mongodb objectid relationship
This commit is contained in:
melohagan 2022-08-23 16:12:18 +01:00 committed by GitHub
commit eeeac38569
2 changed files with 7 additions and 7 deletions

View File

@ -93,8 +93,8 @@ module MongoDBModule {
json[field] = self.createObjectIds(json[field]) json[field] = self.createObjectIds(json[field])
} }
if ( if (
(field === "_id" || field?.startsWith("$")) && typeof json[field] === "string" &&
typeof json[field] === "string" json[field].toLowerCase().startsWith("objectid")
) { ) {
const id = json[field].match( const id = json[field].match(
/(?<=objectid\(['"]).*(?=['"]\))/gi /(?<=objectid\(['"]).*(?=['"]\))/gi

View File

@ -103,16 +103,16 @@ describe("MongoDB Integration", () => {
restore() restore()
}) })
it("creates ObjectIds if the _id fields contains a match on ObjectId", async () => { it("creates ObjectIds if the field contains a match on ObjectId", async () => {
const query = { const query = {
json: { json: {
filter: { filter: {
_id: "ObjectId('ACBD12345678ABCD12345678')", _id: "ObjectId('ACBD12345678ABCD12345678')",
name: "ObjectId('name')" name: "ObjectId('BBBB12345678ABCD12345678')"
}, },
update: { update: {
_id: "ObjectId('FFFF12345678ABCD12345678')", _id: "ObjectId('FFFF12345678ABCD12345678')",
name: "ObjectId('updatedName')", name: "ObjectId('CCCC12345678ABCD12345678')",
}, },
options: { options: {
upsert: false, upsert: false,
@ -126,11 +126,11 @@ describe("MongoDB Integration", () => {
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), _id: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
name: "ObjectId('name')", name: mongo.ObjectID.createFromHexString("BBBB12345678ABCD12345678"),
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
_id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"), _id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"),
name: "ObjectId('updatedName')", name: mongo.ObjectID.createFromHexString("CCCC12345678ABCD12345678"),
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
upsert: false upsert: false