Skip to content

Commit

Permalink
Replace the $where operator with $expr (#101)
Browse files Browse the repository at this point in the history
* Replace the $where operator with $expr

* Update CHANGELOG

* Fix CHANGELOG due error with danger

* Move comment in the same line of expression
  • Loading branch information
amanfrinati authored Mar 6, 2023
1 parent ee29b98 commit 3b26ba2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/locker/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down

0 comments on commit 3b26ba2

Please sign in to comment.