-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Watch insert #219
Comments
It is a problem related to strong type checking. var stream = collection.watch( <Map<String, Object>>[ { '\$match': {'operationType': 'insert'} } ]); Really interesting is the attempt to use the the final pipeline = AggregationPipelineBuilder().addStage(Match(where.eq('operationType', 'insert').map['\$query']));
var stream = collection.watch(pipeline); extracting the |
Thank you. It works now. But there is one interesting thing:
It slows down my code drastically! Do you have any idea why? |
Well, no idea. |
With "request" I mean a http request to my dart api. I am currently developing in a docker enviroment and only have one mongodb instance. No "real" replica set. The watcher works fine, but somehow slows down the other api code. I really have no idea why. I am using other streams with no problem (http request stream). I will continue some try and error :-) |
The final 0.5.0 is out. Did you discover what caused your performance issues? |
Using 0.7.1 on Mongo Server 5.0.2, with 2 secondary replicas, [per this thread] I did:
Everything works great, EXCEPT the onData(event) callback is being called TWICE per insert with exactly the same data. UPDATE: The aforementioned is true as viewed from a debugger. However when I try to get data out of the event it complains: |
I did some test on 4.4 and it seems to work fine. |
Please note that the statement should be final pipeline = AggregationPipelineBuilder().addStage(Match(where.eq('operationType', 'insert').map['\$query'])); |
Am going to try it shortly. But clarification, I wasn't complaining on the data structure sent inside the event. That's common. I am saying that the event fires twice, a few milliseconds apart, with the same data. As-if two inserts just happened. Seems like you are emitting the same event to the stream twice. |
Ok. I tested the example. I am posting the output below.
ps. The funniest part of this is, that how did you know my name, Nathan, when you wrote that test!!!!!!! |
Unless I'm missing something it is exactly what I had (verified after copy of line into my editor). |
Obviously the example code is not exhibiting the duplicate problem, so the problem must be in my code somehow. But I can't figure it out. How do I check why my onData callback gets called twice? |
It is difficult to say why your callback is called twice. If you could provide a small program where your problem can be tested, it could be a great help. The biggest issue in these cases is always to replicate the error. |
I reduced my program to a stripped-down version and it works ok! I think that is somehow related to not await'ing when I should, but not sure about that either. |
Got it! Say the following method that sets up the .watch():
If you call the method multiple times for the same collection, it will not complain. It will happily oblige and create multiple watch cursors for the same collection! (Of course triggering the callbacks for each.) Anyhow, what relief! |
Thanks Nathan for your feedback. I will evaluate your suggestion. |
Hi, I want to detect document inserts in a collection. This is my current try:
I get this error:
Am I doing it right ? This is inspired by https://docs.mongodb.com/manual/reference/method/db.collection.watch/.
I also tried this:
The text was updated successfully, but these errors were encountered: