mongo_fdw icon indicating copy to clipboard operation
mongo_fdw copied to clipboard

Providing custom _id for documents

Open AdamPzpn opened this issue 3 years ago • 3 comments

Trying inserting data into foregin table ends with ignore for _id parameter.

Example: INSERT INTO warehouse VALUES (uuid_generate_v4()::text, 2, 'Laptop', '2015-11-11T08:13:10Z');

Creates: "_id" : ObjectId("53720b1904864dc1f5a571a0"), "warehouse_id" : 2, "warehouse_name" : "Laptop", "warehouse_created" : ISODate("2015-11-11T08:13:10Z")

How can I insert literal _id as string into entity?

AdamPzpn avatar Dec 29 '21 20:12 AdamPzpn

Hi,

Can you please let us know:

  1. How is your table defined on Mongo and
  2. and the definition for it as a foreign table on PostgreSQL.

Regards, Jeevan Ladhe

On Thu, Dec 30, 2021 at 2:12 AM AdamPzpn @.***> wrote:

Trying inserting data into foregin table ends with ignore for _id parameter.

Example: INSERT INTO warehouse VALUES (uuid_generate_v4()::text, 2, 'Laptop', '2015-11-11T08:13:10Z');

Creates: "_id" : ObjectId("53720b1904864dc1f5a571a0"), "warehouse_id" : 2, "warehouse_name" : "Laptop", "warehouse_created" : ISODate("2015-11-11T08:13:10Z")

How can I insert literal _id as string into entity?

— Reply to this email directly, view it on GitHub https://github.com/EnterpriseDB/mongo_fdw/issues/154, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKBZ4VRSU7RFUPRVGFXPADUTNXEXANCNFSM5K6SCK2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

jeevanladhe avatar Dec 30 '21 06:12 jeevanladhe

No problem.

Ad.1

{ "_id" : "1558aeb1-f4fa-4914-82d1-1026d6997976", "param1" : "fa8118db-c004-442d-92e6-00ed3c50a8cb", "param2" : "56cfe38d-c3b7-4ef3-a6f4-ca8799a2b14b", "param3" : "5f6cb622-f8d1-4e08-80ba-0cf3b740641e", "dateFrom" : "2019-10-27T21:19:48Z", "dateTo" : null, "esbSchemaVersion" : 1, "esbExtIds" : [ { "sourceName" : "system", "sourceId" : "456087" } ], "esbVersion" : 1 }

AD.2

CREATE FOREIGN TABLE mongodb.collection( "_id" name NULL COLLATE "C", "param1" text NULL, "param2" text NULL, "param3" text NULL, "dateFrom" text NULL, "dateTo" text NULL, "esbSchemaVersion" int4 NULL, "esbVersion" int4 NULL, "esbExtIds" json NULL ) SERVER mongo_server OPTIONS (database 'mongoDatabase', collection 'collection');

AdamPzpn avatar Dec 30 '21 07:12 AdamPzpn

Hi @AdamPzpn ,

Providing custom _id for a document not supported. Currently, mongo_fdw ignores the value of the first column which is the row identifier in MongoDb (_id) and lets MongoDB insert the unique value for that column.

We will do more studies to try to support this feature in near future.

vaibhavdalvi93 avatar Jan 03 '22 09:01 vaibhavdalvi93