Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Watch command. #32

Open
paradoxewan opened this issue Nov 16, 2018 · 4 comments
Open

Using Watch command. #32

paradoxewan opened this issue Nov 16, 2018 · 4 comments

Comments

@paradoxewan
Copy link

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!

@ozomer
Copy link
Owner

ozomer commented Nov 17, 2018

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

@RichardJohnn
Copy link

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/

@littleyoda
Copy link

littleyoda commented Jun 7, 2020

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

@littleyoda
Copy link

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).

diff.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants