diff --git a/components/mongodb/package.json b/components/mongodb/package.json index 81c29d5f97493..d837a8067b255 100644 --- a/components/mongodb/package.json +++ b/components/mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/mongodb", - "version": "0.1.3", + "version": "0.1.4", "description": "Pipedream MongoDB Components", "main": "mongodb.app.mjs", "keywords": [ diff --git a/components/mongodb/sources/new-document/new-document.mjs b/components/mongodb/sources/new-document/new-document.mjs index 280196df36d14..cabb966072c20 100644 --- a/components/mongodb/sources/new-document/new-document.mjs +++ b/components/mongodb/sources/new-document/new-document.mjs @@ -6,7 +6,7 @@ export default { key: "mongodb-new-document", name: "New Document", description: "Emit new an event when a new document is added to a collection", - version: "0.0.11", + version: "0.0.12", type: "source", dedupe: "unique", props: { @@ -39,6 +39,7 @@ export default { options: [ "Timestamp", "Integer", + "ISO8601", ], }, }, @@ -57,22 +58,32 @@ export default { _setLastTs(lastTs) { this.db.set("lastTs", lastTs); }, - getTs(doc) { - const tsValue = doc[this.timestampField]; + makeTs(timestamp) { if (this.timestampFieldType === "Integer") { - return tsValue; + return timestamp; } - if (typeof tsValue === "string") { - return new Date(tsValue).getTime(); + if (this.timestampFieldType === "Timestamp") { + return this.convertToTimestamp(timestamp); } - try { - return JSON.parse(tsValue); - } catch { - return tsValue; + if (this.timestampFieldType === "ISO8601") { + return new Date(timestamp); } + return timestamp; }, - convertToTimestamp(timestampStr) { - const bigIntValue = BigInt(timestampStr); + getTs(timestamp) { + if (this.timestampFieldType === "Integer") { + return timestamp; + } + if (this.timestampFieldType === "Timestamp") { + return timestamp.getHighBits() * 1_000; + } + if (this.timestampFieldType === "ISO8601") { + return new Date(timestamp).getTime(); + } + return timestamp; + }, + convertToTimestamp(timestamp) { + const bigIntValue = BigInt(timestamp.toString()); const seconds = Number(bigIntValue >> 32n); const increment = Number(bigIntValue & 0xFFFFFFFFn); return new Timestamp({ @@ -90,16 +101,16 @@ export default { }; const query = { [this.timestampField]: { - $gt: this.timestampFieldType === "Integer" - ? lastTs - : this.convertToTimestamp(lastTs), + $gt: this.makeTs(lastTs), }, }; - const documents = await collection.find(query).sort(sort) + const documents = await collection + .find(query) + .sort(sort) .toArray(); const docs = []; for (const doc of documents) { - const ts = this.getTs(doc); + const ts = this.getTs(doc[this.timestampField]); if (!(ts > lastTs) || (max && count >= max)) { break; }