From 3b26ba2ff5cd96047268e2f13980c5a2df961a7b Mon Sep 17 00:00:00 2001 From: Alberto Manfrinati Date: Mon, 6 Mar 2023 21:52:56 +0100 Subject: [PATCH] Replace the $where operator with $expr (#101) * Replace the $where operator with $expr * Update CHANGELOG * Fix CHANGELOG due error with danger * Move comment in the same line of expression --- CHANGELOG.md | 1 + lib/mongoid/locker/wrapper.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd4583..ccb8115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#102](https://github.com/mongoid/mongoid-locker/pull/102): Re-added danger, removed Travis-CI config, extracted RuboCop - [@dblock](https://github.com/dblock). * [#104](https://github.com/mongoid/mongoid-locker/pull/104): Fixed code coverage - [@dblock](https://github.com/dblock). +* [#101](https://github.com/mongoid/mongoid-locker/pull/101): Replace the $where operator with the $expr operator - [@amanfrinati](https://github.com/amanfrinati). * Your contribution here. ### 2.0.2 (2023-01-24) diff --git a/lib/mongoid/locker/wrapper.rb b/lib/mongoid/locker/wrapper.rb index 3568fa2..003999f 100644 --- a/lib/mongoid/locker/wrapper.rb +++ b/lib/mongoid/locker/wrapper.rb @@ -36,7 +36,7 @@ def self.find_and_lock(doc, opts) ] }, { - '$where': "new Date() - this.#{model.locked_at_field} >= #{model.lock_timeout * 1000}" + '$expr': { '$gte': ['$$NOW', { '$add': ["$#{model.locked_at_field}", model.lock_timeout * 1000] }] } # The expr means "Time.now.utc >= model.locked_at_field + model.lock_timeout * 1000" } ] }