node.js - What's the best way to handle insert unique, okay to overwrite? -


i want maintain collection of geographical info ip addresses.

var ipaddressschema = new schema({ ip: {     type: string,     unique: true }, geo: object }, {     strict: true }); 

ips should unique. , if ip exists, should overwrite document.

function storegeotomongo() { emitter.on('inredis', function (geodata, ipstring) {         console.log('.... store geoinfo mongodb ' + ipstring);         ipaddress.findoneandupdate({             ip: ipstring         }, {             ip: ipstring,             geo: geodata         }, { upsert: true }, function (err, document) {             if (err) {                 console.log(err);             } else {                 console.log('successfully saved document');             }         });     } ); } 

is there above should improved? (thanks, neil.)


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -