Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework - Using MySQL and MongoDB for same application

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

like image 772
daydreamer Avatar asked May 23 '11 00:05

daydreamer


People also ask

Can MySQL and MongoDB be used together?

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.

How does MySQL integrate with MongoDB?

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.

Why Use MongoDB over SQL?

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.

Where is MySQL used in real world?

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.


1 Answers

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
like image 70
Ryan Avatar answered Oct 09 '22 23:10

Ryan