Is there a way to automatically delete previous database insertions in my meteor web app whenever a new document is inserted? I've attempted the following code, but it hasn't been successful:
if(SearchLobby.find({profile: Meteor.userId()}).count() > 1){
var date1=SearchLobby.find().limit(1).sort({$natural:-1}).createdAt;
if(SearchLobby.find({profile: Meteor.userId()}).createdAt != date1)
SearchLobby.remove({profile: Meteor.userId()});
}
I'm unsure of alternative approaches to tackle this issue. My initial attempt didn't yield the expected results.