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

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -