Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated collection methods in mongodb-backend.js. Fixes #270 #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/mongodb-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MongoDBBackend.prototype = {
values.forEach(function(value){doc[value]=true;});

// update document
collection.update(updateParams,{$set:doc},{safe:true,upsert:true},function(err){
collection.updateOne(updateParams, {$set:doc}, {w:1, upsert:true}, function(err){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this update call is intended for only one document and not for many documents?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just use update instead of updateOne?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update() is deprecated. I strictly followed the advice in https://mongoosejs.com/docs/deprecations.html to resolve the deprecation warnings and to not change the intended functionality. I used updateOne() because, in this case, update() is only updating the first document found.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a legit change.
But, don't we need to update mongodb version driver in order to use these new functions?

if(err instanceof Error) return cb(err);
cb(undefined);
});
Expand All @@ -135,7 +135,7 @@ MongoDBBackend.prototype = {
transaction.push(function(cb) {
self.db.collection(self.prefix + self.removeUnsupportedChar(collName), function(err,collection){
// Create index
collection.ensureIndex({_bucketname: 1, key: 1}, function(err){
collection.createIndex({_bucketname: 1, key: 1}, function(err){
if (err instanceof Error) {
return cb(err);
} else{
Expand All @@ -161,7 +161,7 @@ MongoDBBackend.prototype = {
transaction.push(function(cb){
self.db.collection(self.prefix + self.removeUnsupportedChar(collName),function(err,collection){
if(err instanceof Error) return cb(err);
collection.remove(updateParams,{safe:true},function(err){
collection.deleteMany(updateParams, {w:1}, function(err){
if(err instanceof Error) return cb(err);
cb(undefined);
});
Expand Down Expand Up @@ -191,7 +191,7 @@ MongoDBBackend.prototype = {
values.forEach(function(value){doc[value]=true;});

// update document
collection.update(updateParams,{$unset:doc},{safe:true,upsert:true},function(err){
collection.updateOne(updateParams, {$unset:doc}, {w:1, upsert:true}, function(err){
if(err instanceof Error) return cb(err);
cb(undefined);
});
Expand Down