Browse Source

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

Mongodb objectid relationship
master
melohagan 4 years ago
committed by GitHub
parent
commit
73573d65b6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      packages/server/src/integrations/mongodb.ts
  2. 10
      packages/server/src/integrations/tests/mongo.spec.js

4
packages/server/src/integrations/mongodb.ts

@ -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

10
packages/server/src/integrations/tests/mongo.spec.js

@ -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

Loading…
Cancel
Save