From df4d3bfa48eed4c3ae9b18a3967830cc66e6a039 Mon Sep 17 00:00:00 2001 From: zeus Date: Sat, 27 Nov 2021 20:23:29 +0200 Subject: [PATCH] man poc --- poc-datacollector/modules/ROOT/nav.adoc | 1 + .../ROOT/pages/doc-readmongo_service.adoc | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc diff --git a/poc-datacollector/modules/ROOT/nav.adoc b/poc-datacollector/modules/ROOT/nav.adoc index 6d3979d..bd668b8 100644 --- a/poc-datacollector/modules/ROOT/nav.adoc +++ b/poc-datacollector/modules/ROOT/nav.adoc @@ -6,5 +6,6 @@ ** xref:index-redis.adoc[Redis] * xref:index-src.adoc[src-files] ** xref:doc-dummy_service.adoc[dummy_service] +** xref:doc-readmongo_service.adoc[readmongo_service] * xref:index-usage.adoc[Usage] ** xref:index-dummy_service.adoc[dummy_service] diff --git a/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc b/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc new file mode 100644 index 0000000..55704c0 --- /dev/null +++ b/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc @@ -0,0 +1,57 @@ += readmongo_service + + +== App + + src: readmongo/swarmlab-app/src/run/ + +=== stream2mongo + +[source,node] +---- + +async function onCollectionNew(err, collection) { + let options = { + tailable: true, + awaitdata: true, + numberOfRetries: -1, + tailableRetryInterval: 500, + }; + var cursor = collection.find({}, options).stream(); + var itemsProcessed = 0; + var room = this.user; + var sid = this.id; + console.log("Inside callback: " + room + " Id: " + sid); + var rep = setUser(sid, room); + + cursor.on("data", async function (data) { + cursor.pause(); + var res = await getkey(sid); + + if (res == "1") { + cursor.resume(); + var obj = JSON.parse(JSON.stringify(data)); + io.in(room).emit("logsend", obj); + } else if (res == "2") { + cursor.resume(); + console.log("Cursor is closing..."); + cursor.close(); + } + }); +} + +---- + + +=== restart + +To make changes become effective a restart is *not* required + + + + + + + + +