Is it possible to user MySQL Database
and MongoDb
database for same project using Play! framework?
for example: I want
@Entity Person to interact with my MySQL database and
@Entity PersonData to interact with my MongoDB database?
How can I do that?
Please let me know
Thank you
It's common to use MySQL as the primary storage and MongoDB as caching/intermediate storage for speed. You can for example have read-intensive data in MongoDB. The data for generating reports is perfect for a relational system like MySQL.
Connect to MongoDB through the SQL GatewayIn MySQL Workbench, click to add a new MySQL connection. Name the connection (CData SQL Gateway for MongoDB). Set the Hostname, Port, and Username parameters to connect to the SQL Gateway. Click Store in Vault to set and store the password.
Let us summarize our discussion below. SQL databases are used to store structured data while NoSQL databases like MongoDB are used to save unstructured data. MongoDB is used to save unstructured data in JSON format. MongoDB does not support advanced analytics and joins like SQL databases support.
MySQL is a relational database management system based on SQL – Structured Query Language. The application is used for a wide range of purposes, including data warehousing, e-commerce, and logging applications. The most common use for mySQL however, is for the purpose of a web database.
Yes, it is possible. Just use the Morphia plugin for Play. I have done it before. It is quite simple.
For the MongoDB models, just do something like this:
import play.modules.morphia.Model;
@Entity
public class YourMongoModel extends Model {
...
}
For the MySQL model, do this:
import play.db.jpa.Model;
@Entity
public class LogMessageX extends Model {
...
}
Notice the different imports.
Then the application.conf file should contains something like this:
# For MongoDB
morphia.db.host=localhost
morphia.db.port=27017
morphia.db.name=YourMongoDBName
# for MySQL
db=mysql:user:pwd@database_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With