Locating and updating Scala object data using Play Framework and MongoDB
Add MongoDB Scala driver library dependencies to build.sbt.
Storing database connection parameters in the application configuration file helps to avoid “hard-coding” the variables and makes it easy to change the server location as well as the name of the database. Add the following entry to conf/application.conf and update the database name:
Server key points to where the database engine is running. In this case, the database is running on the same machine as the application.
Database key is the name of the database to be created and used by the application. In this case, the database is named sample.
The method uses driver's replaceOne operation thread to remove the original document and insert the new one while keeping the document id.
Browse related articles