Skip to content

put duplicate #120

Answered by kriszyp
cekvenich2 asked this question in Q&A
Dec 26, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Doing a put with dupSort: false with an entry that already exists will replace it. So:

db = open(...); // no dupSort
db.put('key', 'first value');
db.put('key', 'second value'); // replaces the value for 'key'
await db;
db.get('key'); // returns 'second value' 

LMDB does have an option for doing puts that will only execute if there is no existing entry and fail if there is an existing entry:

db.put('key', 'second value', { noOverwrite: true });
// or
db.ifNoExists('key', () => db.put('key', 'second value'));

Both of these will (return a promise that) resolves to false if there is already an existing entry.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cekvenich2
Comment options

Answer selected by cekvenich2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants