Created
April 12, 2016 11:57
-
-
Save simon-p-r/f043d8885115549a90d327a34c87cf1a to your computer and use it in GitHub Desktop.
Nedb generating duplicate records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"cui","encodedLicence":"someString","_id":"MQOifltLiOJh68oJ"} | |
{"name":"cui","encodedLicence":"someString","_id":"MQOifltLiOJh68oJ"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Assert = require('assert'); | |
const Fs = require('fs'); | |
const filename = 'bugreport.db'; | |
const onload = function(err) { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
}; | |
const DB = require('nedb'); | |
const db = new DB({ | |
autoload: true, | |
filename: filename, | |
onload: onload | |
}); | |
const doc = { | |
name: 'cui', | |
encodedLicence: 'someString', | |
}; | |
const options = { | |
upsert: true | |
}; | |
db.update({ name: 'cui' }, doc, options, (err, results) => { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
Assert(results === 1); | |
db.update({ name: 'cui' }, doc, options, (err, results) => { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
Assert(results === 1); | |
process.exit(0); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"nedb": "^1.8.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment