Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/mongodb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/mongodb",
"version": "0.1.3",
"version": "0.1.4",
"description": "Pipedream MongoDB Components",
"main": "mongodb.app.mjs",
"keywords": [
Expand Down
45 changes: 28 additions & 17 deletions components/mongodb/sources/new-document/new-document.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -39,6 +39,7 @@ export default {
options: [
"Timestamp",
"Integer",
"ISO8601",
],
},
},
Expand All @@ -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({
Expand All @@ -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;
}
Expand Down
Loading