我想做一个活动系统,每个活动都有很多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如何查询?
PHP中文网2017-04-22 08:58:05
If the amount of data is large and it takes a lot of effort, you can consider combining MySQL and Sorl.
The amount of data is not large, so you can consider using tags as a category and save them in MySQL.
MySQL is not as slow as you think.
大家讲道理2017-04-22 08:58:05
MongoDB is obviously good, but using a relational database to do this is simply a disaster
ringa_lee2017-04-22 08:58:05
MongoDB model design is best not designed like that, it should be like the following
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"]}
}
And build the corresponding index
PHP中文网2017-04-22 08:58:05
Just a little advice: Don’t use technology that you can’t control.
Use whichever one you are familiar with and whichever one you are more proficient in.
If you have not used either, you can consider MongoDB.
ringa_lee2017-04-22 08:58:05
For the Tag system, I feel it would be more convenient to use redis. For this problem, you can just use SET in redis.
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.
If you use mongo for other parts, you can also use redis for individual real-time updated tag increases and decreases and for event increases and decreases in a certain tag.
If you want to record the number of times each tag has been adopted, just add a HASH with the tag text as the key and the number of adoptions as the value.