Asnad Atta
Asnad Atta

Reputation: 4003

Increment in column for all records in one query with mongodb and rails

I have asked similar question here but same thing I need to do with mongodb how can I add increase every single record's created_at column. For example I have three records with timestamp 1,5 and 20 I want increment by 5 and these would become 6,10,25 respectively in one query. The purpose is to avoid loop for thousands of records.

Upvotes: 0

Views: 139

Answers (1)

ashusvirus
ashusvirus

Reputation: 412

You can use $inc operator from mongodb

Rails usage

CollectionName.collection.update_many({query}, {"$inc": {"field_name": value_to_inc_with}})

Upvotes: 1

Related Questions