Upserting keeps adding duplicates of the same record to the database
See original GitHub issueSee the code below, upserting the same record three times in a row:
var Nedb = require('nedb');
var db = new Nedb({ filename: 'test.db' });
db.loadDatabase(function (err) {
db.update({ '_id': 'foo_id' }, { somedata: 'hello' }, { 'upsert': true }, function (err, numReplaced) {
console.log(numReplaced, err);
db.update({ '_id': 'foo_id' }, { somedata: 'hello' }, { 'upsert': true }, function (err, numReplaced) {
console.log(numReplaced, err);
db.update({ '_id': 'foo_id' }, { somedata: 'hello' }, { 'upsert': true }, function (err, numReplaced) {
console.log(numReplaced, err);
});
});
});
});
At the end of execution, test.db is:
{"somedata":"hello","_id":"foo_id"}
{"somedata":"hello","_id":"foo_id"}
{"somedata":"hello","_id":"foo_id"}
I’m on Mac OS Yosemite (10.10.1) running nodejs 0.10.33 and nedb 0.11.1. This issue goes well with the other one I found some time ago https://github.com/louischatriot/nedb/issues/217 . Thanks!
Giacecco
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to Avoid Inserting Duplicate Records in SQL INSERT ...
This article discusses inserting records from another table or tables using an INSERT INTO SELECT statement without duplicate key errors.
Read more >Why does upsert cause a DUPLICATE_VALUE error?
Because, both the records that you are inserting are having same name ... any duplicates so it goes ahead with the INSERT and...
Read more >Duplicate records are created during upsert in Apex batch job.
I need to extract records from an external application database table and Create a new table (custom object named CustomObj) in Salesforce ...
Read more >One row, many threads: How to avoid database duplicates in ...
We talk about PostgreSQL, but the same idea applies to MySQL and other SQL databases. To create a new uniqueness constraint with an...
Read more >How To Avoid Inserting Duplicate Records in MySQL - Ubiq BI
If we use INSERT statement to add data with duplicate rows, MySQL will throw an error and stop query execution after the first...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@louischatriot I come accross to this problem also, it would be better to make a notice in a subsection of update/delete section. no one reads the whole readme fro a simple update documentation. Thanks!
This is the expected bahavior, please read the readme before asking about sutff in it …