Mongoose IP Addresses
Mongoose models
Store IP addresses in yourInstall
npm install --save mongoose-ip-address
Usage
// some-model.js var mongoose = ;var ipAddressPlugin = ; var SomeSchema = ...;SomeSchema;var SomeModel = db; moduleexports = SomeModel
// Using your model var mongoose = ;var SomeModel = ; mongoose; someModelInstance = SomeModel // Alternately, use =someModelInstanceip_address = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"; // string, can be IPv4 or IPv6 someModelInstance console; // Stringconsole; // Buffer
This will add the fields you specify in the fields
argument as virtuals to your schema. It will actually store the IP address as a Buffer
in MongoDB, but it will allow you to get and set these fields as strings.
There are many advantages to this. For example, it makes grabbing entries by a range of IP addresses much easier.
var ip = ; var ip_range_start = ipvar ip_range_end = ip SomeModel;
TODO
- Allow better integration if the fields are already part of the schema, or you want to set more options on them
- Validation
- Unit tests...
Bugs and pull requests
Please use the github repository to file bugs and make pull requests.
License
This software is released under the MIT license. Use it, fork it.