简体   繁体   中英

Naming convention for MongoDB in combination with Play Framework (Scala)

With regards to mongoDB, then everything is clear and on this subject much has been written. Use javascript syntax (first_name and even better "fn" to save space). But what about the work in the scala code (I use camelCase). For example, I would have written such a hierarchy

case class User (... personalInfo: PersonalInfo, ...)
case class PersonalInfo (... fullName: FullName, ...)
case class FullName (firstName: String, middleName: Option [String], lastName: String)

If I want to work with mongoDB simply (namely use JSON Macro Inception and do not write custom readers and writers), I must change these classes something like this

case class User (... p_inf: PersonalInfo, ...)
case class PersonalInfo (... f_nm: FullName, ...)
case class FullName (fn: String, mn: Option [String], ln: String)

But this code looks ugly for me (as the reduction of words, and a whole style)

val firstName = user.p_inf.f_nm.fn

I'm going to make another constant for the fields, which are then used in javascript/html code (and here this style is suitable), for example

trait JsFields {
val jsFirstName = "p_inf.f_nm.fn"
}

user.scala.html:

import ... JsFields._
<input name="@jsFirstName" />

So MongoDB and JS/html styles are appropriate, but the business logic is not. Please write best naming practice in conjunction MongoDB/Play Framework with Scala/Html/JS. Please with examples (eg fields above).

Mongo 3 adds compression with the Wired Tiger engine, so you probably don't need or want to use obscure names anymore.

https://comerford.cc/2014/11/12/mongodb-2-8-new-wiredtiger-storage-engine-adds-compression/

The actual JIRA ticket where it was implemented: https://jira.mongodb.org/browse/SERVER-164

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM