首页 > 想做一个多tag的 系统用MongoDB好还是常规的MySQL好?

想做一个多tag的 系统用MongoDB好还是常规的MySQL好?

我想做一个活动系统,每个活动都有很多tag, 当然有参加的人数,时间,地点。最近学习了mongodb 感觉如果用mongo会很方便:
meeting table:

{_id: 42, name: "someName", tags: ["chicken", "parrot", "hovercraft"]}

person table:

{_id: "somebody@gmail.com", name:"LiMing", phone:"1381671537"}

person activity table:

{_id:56, person: "somebody@gmail.com", eventid: 42}

每个活动都会有很多人参加。我不知道如果系统大了,特别是参加的多了用mongodb好呢,还是用传统数据库mySQL好呢? 还有查询效率,比如:

db.meeting.find({tags:{$in:["tag2", "tag1"]}});

这样高么? 传统数据库要用多对多表,不知道传统查询速度高还是直接用mongoDB这样速度快。 本来想设计成一张表,如果活动人很多人参加 比如 person有 200人,会不会降低效率?
有时候怕加人减人台频繁会不会有锁的问题,比如同时添加多个人到某此活动中?
mongoDB多个表join如何查询?


mongoDB 模型设计最好不像那样设计,应该像下面

meeting table:
{_id: 42, name: "someName", tags: ["chicken", "parrot", "hovercraft"]}

person table:
{_id: "somebody@gmail.com", name:"LiMing", phone:"1381671537"}

person activity table:
{_id:56, person:
{_id: 42, name: "someName", tags: ["chicken", "parrot", "hovercraft"]},
event: {_id: 42, name: "someName", tags: ["chicken", "parrot", "hovercraft"]}
}

并建好对应的索引


mongodb吧。没有原因,就是喜欢。


Tag系统的话,感觉用redis会更方便一点。对于这个问题,在redis里面可以用SET就可以了。

http://redis.io/topics/data-types

Redis Sets are good to represent relations. You can create a tagging system with Redis using a Set to represent every tag. Then you can add all the IDs of all the objects having a given tag into a Set representing this particular tag, using the SADD command. Do you want all the IDs of all the Objects having a three different tags at the same time? Just use SINTER.

如果你其他部分使用mongo的话,单独的实时更新的tag增减和某个tag中对于event的增减也可以用redis。

如果要记录每个tag的被采纳次数,再加一个以tag文本为key,以采纳数为value的HASH就可以了。


只有一点儿忠告:别用自己驾驭不了的技术

哪个熟悉,哪个你比较精通,就用哪个。

如果两者都没用过,可以考虑 MongoDB。


数据量大,要花大力气搞的话 可以考虑 MySQL 和 Sorl 结合。

数据量不大,完全可以考虑把tag作为一个分类去做,保存在MySQL。

MySQL没有你想的那么慢。


这种明显MongoDB好啊,用关系型数据库搞这个,简直是遭罪

【热门文章】
【热门文章】