문제

How do you increment multiple fields in one query in mongoose?

For example, here is the working mongo query that I want to use with a mongoose model.

db.users.update({ userId:89 }, { $inc : { "subjectResults.attempts" : 1, "subjectResults.total_time" : 10, "subjectResults.total_score" : 100 } })

The above query is working in plain vanilla Mongo.

Edit: I have removed the confusing property name that lead to the comments below.

도움이 되었습니까?

해결책

The APIs are nearly identical. Instead of db.users.update in straight mongodb, it's UserModel.update in mongoose. Pass in the exact same query and update options object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top