1

Is there an option to not touch the updated_at attribute when i update an attribute in mongoid ?

Something similar to model.save(validate: false) or, better, model.update_attribute(:attribute, 'value') ?

JoJoS
  • 1,971
  • 2
  • 13
  • 15
  • You can do it outside of active record assuming you're using Rails. See https://stackoverflow.com/questions/14816900/how-to-query-mongodb-directly-from-ruby-instead-of-using-mongoid#17537735 – lacostenycoder Sep 25 '17 at 09:37

2 Answers2

1

I just found my answer here : https://github.com/mongoid/mongoid/blob/v3.1.7/lib/mongoid/timestamps/timeless.rb

If anyone is interested, you can use model.timeless to skip updating created or update date, and model.clear_timeless_option to reactivate it !

JoJoS
  • 1,971
  • 2
  • 13
  • 15
-1

You can use the update_column method:

https://apidock.com/rails/v3.1.0/ActiveRecord/Persistence/update_column

Validations are skipped.

Callbacks are skipped.

updated_at/updated_on are not updated.

Ronan Lopes
  • 3,320
  • 4
  • 25
  • 51