I have appx 1.5 lakh records and try to insert into mongodb. The problem is that when I use Meteor.call method and send that to insert into mongodb. It take time i need any indication how much record are pending or progress bar. Can you give me any example for that
What does your insert method look like? Are you doing a bulk insert?
I am using just like Meteor.Call([Array],[Callback])
I m using just like Meteor.Call([Array],[Callback])
Okay, but what does your server side code look like?
If you are sending 150k documents from client to server and then inserting using a loop on the server, then you are inevitably going to get huge delays, both in network transfer time and in server insert time.
As @vigorwebsolutions has asked - we need to see your code.
//Server side
mappedHeader:function(data){ //toId
Companies.remove({});
for ( let i = 0; i < data.length; i++ ) {
Companies.insert(data[i]);
}
}
Yes - that must be the worst possible way to do this.
- Why are you sending data from the client? Can the data be made available to the server directly (without this huge overhead)?
- Looping through an array is not an optimal way to do a bulk insert. Check this blog post.
-
I am reading CSV file through upload and after that user will be mapped record on page then send data to server. Also i need a progress bar to show records status off records.
-
For Looping i need values save as table format. If i sent whole data at once then save in single array node.
I have resolved progress bar issue using observeChanges. “https://docs.meteor.com/api/collections.html#Mongo-Cursor-observeChanges” . But still have performance issue.
If your data is coming from a REST endpoint, can you use a server-side method to get that data when the user clicks a button? So, the client doesn’t get involved in the data transfer.
Use yourCollection.rawCollection().insertMany
on the server.