Reputation: 1
I have a contacts table in a mysql database and an event/action log database in mongodb. Items in action log belongs contacts.
id | name | email
1 | Joe | [email protected]
{_id:..., contact_id: 1, type:"purchase", data:{}}
{_id:..., contact_id: 1, type:"signup", data:{}}
{_id:..., contact_id: 1, type:"click", data:{}}
This is very easy since, I just need to run a mongo .find({type:"purchase"})
, iterate through contact ids and query the mysql database.
This is where I'm stuck, only option that came to my mind was doing .find({type:"purchase"})
, grab the contact ids and put them inside a NOT IN()
, but it's not going to work for the long run, what would be scalable approach to run a query like this?
Same problem as again, first I need to run the mysql part and get contacts who's email starts with "joe" and then use those ids in mongo, or reverse which ever the way where there's less data (contact ids)
I'm not sure if moving the contacts table to a mongo collection will make it easy since in mongo this kind of relationship still requires multiple query runs.
Thanks for the input.
Upvotes: 0
Views: 84
Reputation: 1
If all your data are in mysql, then you need a JOIN operation to finish it in one query. Mongodb is not support JOIN. Maybe you can redundancy the CONTACTS data to Events.
Upvotes: 0
Reputation: 309008
It'd be either/or for me, not both. Logging databases should be separate from transactional ones. If you can't put everything in MongoDB, I'd have all the transactional stuff in MySQL. Duplicate the data in both, do the transactional JOINs in MySQL, and don't mingle the two when querying.
Upvotes: 1