Using Watch command.
paradoxewan opened this issue · 4 comments
Hi there, trying to use the watch command,
msg.collection="jobs";
msg.operation="watch";
var pipeline = null;
var options ={
fullDocument:"default"
};
msg.payload = [pipeline,options];
return msg;
im getting error
"TypeError: Cannot create property 'readPreference' on number '1542372194371'"
Any ideas? Thanks!
I've never tried the watch command.
Are you able to run it directly with the native mongodb package?
http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#watch
I saw that TypeError when I had an inject node with the default timestamp being sent.
Are you using a function block with that code in it as the input to the watch, @paradoxewan ?
I haven't figured out how to use the watch command, in node-red yet. With the native package you keep a reference to the cursor and use a while loop on it https://docs.mongodb.com/manual/reference/method/db.collection.watch/
nodered
Has anyone successfully used the watch command with nodered?
For your information my flow is attached, which I have used for testing. Unfortunately it does not work.
flow.txt
node.js
I was able to test it successfully in node.js:
server_js.txt
based on https://levelup.gitconnected.com/taking-advantage-of-mongodbs-change-streams-for-real-time-iot-applications-using-nodejs-a0a76ae1376d
I looked into the problem further. The underlying library returns a ChangeStream Object. Currently the return value is ignored.
I tried to change mongodb.js to take care of this ChangeStream Object. (see the attached diff)
This change is still far from a productive solution. Someone with nodered experience has to check my work and certainly have to improve it (see all the TODOs).