I have been searching for various Q&A on ways to efficiently save and sort IPs in a mongo db, but I am struggling to find a solution. Firstly: how should I save an IP address? As a string? Integer? Something else? Secondly: Once saved (let's say from 10.1.0.20 to 10.1.1.255), I need to retrieve the highest IP in my database and then increment it by 1. How can I achieve this? What is the most effective method for retrieval? Is using
this.model.findOne().sort({"staticIp": -1}).exec();