How to update object in Mongo with an immutable Salat case class

后端 未结 3 1113
遥遥无期
遥遥无期 2021-01-24 16:51

I\'m working on a project with Scala, Salat, Casbah, Mongo, Play2, BackboneJS... But it\'s quite a lot of new things to learn in the same time... I\'m ok with Scala but I find m

3条回答
  •  春和景丽
    2021-01-24 17:19

    There are really two problems in your question:

    1. How do I use Play Salat.
    2. How do I prevent updates to certain fields.

    The answer to your first question lies in the Play Salat documentation. Your second question could be answered a few ways.

    a. When the update is pushed to the server from Backbone, you could grab the object id and find it in the database. At that point you have both copies of the object. At that point, you can fire a business rule to make sure the sender didn't attempt to change those fields.

    or

    b. You could put some of your fields in another document of an embedded document. The client would have access to them for rendering purposes but your API wouldn't allow them to be pushed back to Mongo.

    or

    c. You could write a custom update query that ignores the fields you don't want changed.

提交回复
热议问题