Change stream not published when data is edited with MongoDB Compass - mongodb-compass

As the title suggest, when I make changes to data using MongoDB compass, the changes are not being published in the change stream. I have a Node.js service which listens to the change stream.

Same issue here. Changes were not published to stream when editing data in Robo3T. I can see changes in Mongo change stream when data is being edited via Spring Boot application.
The issue got fixed after adding replace operation type in watch list.
collection.watch(singletonList(Aggregates.match(Filters.in("operationType", asList("update", "insert","**replace**")))))

Related

How do i know all my changes made to document in offline mode are synced to firestore when i turn on internet in flutter firestore

I am creating flutter app, where I am using Cloud Firestore as a database and I am utilizing its offline capability. the app perfectly works when I am in offline mode it saves documents locally and when I turn on the internet it syncs those documents back to Firestore.
I want to know is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?
I didn't find anything in the documentation.
I want to know if is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?
Yes, you can know that in Flutter too. So please check the SnapshotMetadata of a QuerySnapshot object, which contains an isFromCache field that:
Whether the snapshot was created from cached data rather than guaranteed up-to-date server data.
If your Flutter project requires you to listen for metadata changes, then please check the official documentation:
If you want to receive snapshot events when the document or query metadata changes, pass a listen to options object when attaching your listener:
final docIdRef = db.collection("collName").doc("docId");
docIdRef.snapshots(includeMetadataChanges: true).listen((event) {
//Your logic.
});
In this way, you'll be able to update the UI elements of your screens, once the data is synchronized with the Firebase servers.

How to send mongodb collection updates in Spark streaming context?

How to send the data from a mongodb collection whenever it gets updated to spark streaming context. I have seen socketTextStream to write the data to mongodb. But is there any way to read the stream when the collection gets updated? Is there any way to avoid to implement Custom Receiver for mongodb ? Or If anyone has already implemented, then it will be nice, if someone can share.
Thanking you for any input on this.
One way to achieve this is using the CDC pattern where on one side you have the reactive mongo library that can hook onto a collection and receive events like update, insert, delete from the mongodb and on the other side you have a spark streaming application that will listen on this events.
The transport engine of the events can be any publish/subscriber system (e.g Kafka)

How to use stream listener i.e db.collection.watch() in mongodb and flutter

Hi I want to listen to data changes in mongodb using the db.collection.watch() function. Could any one let me know how to use it. I am using mongodart package run in AWS EC2 server.
The attached image is a collection name 'cart' . I want to listen to it whenever a change is made that is a document is added or deleted it would change the count .
Earlier i used firestore where i can use stream builder to do so. But i am new to app development so learning daily . It would be helpful if any one could let me know how to use it

MongoDB: How to add a hashfield which automatically updates with new hash of document whenever data changes?

The title of this question is the entire question already:
Is there a way to add a field to a MongoDB document that automatically updates with the new hash of the documents whenever the internal data of this document changes? _id can't be used for this task.
Mongo doesn't have built in triggers.
They recently-ish launched mongo stitch a BaaS of theirs that has trigger support (i'm not sure to what extend as i personally don't use it).
With that said ALL database changes that happen in the mongo are logged into a log file, if you want to create a custom parser you could listen to change in that log and identify the changes you need, however this might approach be overkill for your purposes.

Syncing Database (sqlite) from WebService(Json/XML) for iOS

I have a Web Service and sqlite database. In this, web service will be used to store data inside database. Now I want to include sync functionality as - Whenever application starts at that time the database will start to load its table's data through web service.
Now after some time when I update my my web service the database will be updated accordingly. My question is that what are the best practices that I must follow for this update. Should I clear whole DB and start adding all rows again(I know this will take a lot time) but If not this then how do my database will add only particular data from the web service?
Thank you.
What I suggest you is:
store all your webservice content into db first when the app starts.
display your content on the screen from db only.
again when you need to refresh or recall your data just update the database.
Thus, you will always find all your fresh data into database.
Downloading and updating the entire server data will prove expensive. It will use more bandwidth and prove costly to your customer. Rather than pushing the entire load (even for minor update), send a delta. I will suggest you to maintain version information.
When application downloads the data from web service for a said version and store it successfully in the database, set the current updated version as well in the DB.
When app starts the next time, make a light weight header request to get just the version info from the server. The server should respond to this header request with the latest data version number.
Check the version from WS with the current application data version stored in the DB. If the server has an updated version, start the sync.
The version change information should be delta i.e.
For new version, server should send only the information that is changed since the version available with the device.
You server should have capability to calculate the delta between two versions.
Delta information will typically have sections like, new data, updated data, deleted data etc.
Based on this, the iOS app will make the necessary CRUD(Create, Read, Update and Delete) operations on the DB data.
Once the iOS app updates itself, then you can update the DB version to the latest received version from server. Until then let it remain dirty for proper error handling.
Hope that helps.
I would recommend you use RestKit's superb Core Data support.
By using RKEntityMapping you can map your remote objects from JSON or XML directly to Core Data entities in your database.
RestKit will automatically maintain the database for you, inserting and updating entries as appropriate from your web service. (In my experience, I've found deleting objects requires a tiny bit of extra work depending on how RESTful your web service is).
RestKit definitely does have a learning curve attached, but it's well worth it: having deployed it a couple of times now, is definitely a much better solution than manually writing your own SQLite/Web Service syncing code.
First you need to set all webservice content into your SQLITE.and what you want to display get that data from SQLITE.and perform opertaion into that sqlite table and when once all this done you need to changes made are saved it into webservice.
Follow this way.