From 10a345a5554c8e93d67aae18e3b4747f2287ed93 Mon Sep 17 00:00:00 2001 From: Renzo Pigliacampo Date: Mon, 23 Aug 2021 02:45:53 -0300 Subject: [PATCH 1/3] NeDB findOneAndUpdate(): Add 'manual' option to allow field modifiers --- README.md | 2 +- lib/clients/nedbclient.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c1c959..c11c2d2 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ Once a document is saved, it will automatically be assigned a unique identifier If you specified a default value (or function) for a schema variable, that value will be assigned on creation of the object. -An alternative to `.save()` is `.findOneAndUpdate(query, update, options)`. This static method will find and update (or insert) a document in one atomic operation (atomicity is guaranteed in MongoDB only). Using the `{upsert: true}` option will return a new document if one is not found with the given query. +An alternative to `.save()` is `.findOneAndUpdate(query, update, options)`. This static method will find and update (or insert) a document in one atomic operation (atomicity is guaranteed in MongoDB only). Using the `{upsert: true}` option will return a new document if one is not found with the given query. For NeDB, you can use the option `{manual: true}` to specify field modifiers manually (see NeDB [docs](https://github.com/seald/nedb#updating-documents) for a complete list). ### Loading diff --git a/lib/clients/nedbclient.js b/lib/clients/nedbclient.js index a5ba0c7..d1505ef 100644 --- a/lib/clients/nedbclient.js +++ b/lib/clients/nedbclient.js @@ -237,7 +237,7 @@ class NeDbClient extends DatabaseClient { return resolve(null); } } else { - return db.update(query, { $set: values }, function(error, result) { + return db.update(query, options.manual ? values : { $set: values }, function(error, result) { if (error) return reject(error); // Fixes issue #55. Remove when NeDB is updated to v1.8+ From 763562179c72e95bb51f841853f7feae54dc8eb9 Mon Sep 17 00:00:00 2001 From: Renzo Pigliacampo Date: Thu, 9 Dec 2021 16:47:09 -0300 Subject: [PATCH 2/3] NeDB isNativeId(): Allow dashes (-) to be included in the ID string --- lib/clients/nedbclient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/clients/nedbclient.js b/lib/clients/nedbclient.js index d1505ef..87f4114 100644 --- a/lib/clients/nedbclient.js +++ b/lib/clients/nedbclient.js @@ -468,7 +468,7 @@ class NeDbClient extends DatabaseClient { * @return {boolean} */ isNativeId(value) { - return String(value).match(/^[a-zA-Z0-9]{16}$/) !== null; + return String(value).match(/^[a-zA-Z0-9-]{16}$/) !== null; } /** From e5bd059fa95df7c26552908144598aaf1169e178 Mon Sep 17 00:00:00 2001 From: Renzo Pigliacampo Date: Thu, 9 Dec 2021 16:48:57 -0300 Subject: [PATCH 3/3] NeDB isNativeId(): Remove ID character length limit --- lib/clients/nedbclient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/clients/nedbclient.js b/lib/clients/nedbclient.js index 87f4114..a291a82 100644 --- a/lib/clients/nedbclient.js +++ b/lib/clients/nedbclient.js @@ -468,7 +468,7 @@ class NeDbClient extends DatabaseClient { * @return {boolean} */ isNativeId(value) { - return String(value).match(/^[a-zA-Z0-9-]{16}$/) !== null; + return String(value).match(/^[a-zA-Z0-9-]*$/) !== null; } /**