simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.17k stars 223 forks source link

mongodb support? #76

Closed TangMonk closed 9 years ago

simov commented 9 years ago

Express Admin is designed for relational databases.

In the cases where I'm making separate queries to get the data for each referenced table it won't matter. But think about the cases where you need to aggregate data across multiple tables.

For the ListView:

select 
concat_ws(',',`tbl`.`id1`,`tbl`.`id2`) as `__pk`,
group_concat(distinct concat_ws(' ',`otm16`.`name1`)) as `otm1_id`,
group_concat(distinct concat_ws(' ',`otm27`.`name1`,`otm27`.`name2`)) as `otm2_id`,
group_concat(distinct concat_ws(' ',`mtm18`.`name1`)) as `mtm1`,
group_concat(distinct concat_ws(' ',`mtm29`.`name1`,`mtm29`.`name2`)) as `mtm2` 
from `tbl` 
left join `otm1` `otm16` on `tbl`.`otm1_id1`=`otm16`.`id1` and `tbl`.`otm1_id2`=`otm16`.`id2` 
left join `otm2` `otm27` on `tbl`.`otm2_id1`=`otm27`.`id1` and `tbl`.`otm2_id2`=`otm27`.`id2` 
left join `tbl_has_mtm1` on `tbl`.`id1`=`tbl_has_mtm1`.`tbl_id1` and `tbl`.`id2`=`tbl_has_mtm1`.`tbl_id2` 
left join `mtm1` `mtm18` on `tbl_has_mtm1`.`mtm1_id1`=`mtm18`.`id1` and `tbl_has_mtm1`.`mtm1_id2`=`mtm18`.`id2` 
left join `tbl_has_mtm2` on `tbl`.`id1`=`tbl_has_mtm2`.`tbl_id1` and `tbl`.`id2`=`tbl_has_mtm2`.`tbl_id2` 
left join `mtm2` `mtm29` on `tbl_has_mtm2`.`mtm2_id1`=`mtm29`.`id1` and `tbl_has_mtm2`.`mtm2_id2`=`mtm29`.`id2`  
group by `tbl`.`id1`,`tbl`.`id2` order by `tbl`.`id1` asc limit 0,2 ;

There is no notion of relation in document oriented databases. The only 'join' you can make is if you have your referenced data embedded into array in that same document. Then you can use the aggregation framework to unwind it and make queries on that. Otherwise you are going to make separate queries each time you would normally have join and do the aggregation by yourself.