I'm trying to save a location of delivery guy in the database for each 1 second.
Using socket io, I listen to the client (delivery guy) and print his location and save it using mongoose.
It works when the socket listens to low number of clients. But I tried to listen to 5000 clients simultaneously, the saving operation is not getting executed.
Here is my code
io.of('/orders').on('connection', (socket) => {
socket.on('driver-location', async ({ id, location }) => { // Listing to `driver-location` event.
try {
console.log(`${id} - driver's Location: ${location}`); // Console id and location, getting executed !
var lat = parseFloat(location.split(',')[0]); // Get latitude
var lng = parseFloat(location.split(',')[1]); // Get longitude
var newLocation = new Location({ // Create new location with attributes
name: 'Mock Name',
order_id: '####',
location: {
type: 'Point',
coordinates: [lng, lat]
},
});
let saved = await newLocation.save(); // Not getting executed !
return saved; // end of function
} catch (error) {
return console.log(error);
}
});
});
I would really appreciate your help, if there is questions regarding my code please feel free to ask.