what is the best way to create document inside collection in MongoDB
I'm using PHP and MySQL for social net work system
I have MySQL table named member_feed , in this table I save feeds for each member, my table structure is :
|member_feed_id | member_id | content_id | activity_id |
in this table I have more than 120 million record , and every member has set of record.
I currently work to migrate from MySQL to MongoDB and I'm new on MongoDB . so I need to convert this table to collection in MongoDB . I think to build my collection for member_feed table like :
1- each row from member_feed table as document , like:
{ "member_id: 1" , "content_id: 10" , "activity_id: 1" },
{ "member_id: 1" , "content_id: 11" , "activity_id: 2" },
{ "member_id: 1" , "content_id: 12" , "activity_id: 3" },
{ "member_id: 2" , "content_id: 9" , "activity_id: 4" },
{ "member_id: 2" , "content_id: 11" , "activity_id: 5" },
{ "member_id: 2" , "content_id: 14" , "activity_id: 6" }
so this collection will have 120 million record
2- all member feed for one document that have member id and all feeds for this member
{
member_id: '1',
feeds: [
{ content_id: '10', 'activity_id' : 1 },
{ content_id: '11', 'activity_id' : 2 },
{ content_id: '12', 'activity_id' : 3 }
]
member_id: '2',
feeds: [
{ content_id: '9', 'activity_id' : 4 },
{ content_id: '11', 'activity_id' : 2 },
{ content_id: '14', 'activity_id' : 6 }
]
}
so when I need to view user feed on his dashboard I will do :
1-get all ids from document inside mongoDB as $contentIdsFromMongo
by member_id
2- run query in MySQL to get the content like
select * from content where content_id in($contentIdsFromMongo);
and $contentIdsFromMongo my be have 10000 ids , so is this affect to MySQL performance.
and I have mongoDB on server and MySQL on another server
and in every second the system insert a lot of record for each member, so I need the document to be able to do all operation like (insert, update, select,..)
what is the best way to create the documents in collection for each member, and is this way right or wrong for working with mongoDB
Thanks.
Two main considerations in data modelling for document stores:
You have provided info around how data is expected to grow. Just on that basis, I would suggest option #1.
{ "member_id: 1" , "content_id: 10" , "activity_id: 1" }
But, it is also important to understand what kind of queries you will be performing and how you intend to use this data in your application.
Additional options possible are:
So in summary, to come up with an optimal model, answering question 2 above is also important.
PS: Option 2 in your question definitely sounds like a bad idea given how you have described data will grow.
You may also refer to this link for some additional guidelines: http://docs.mongodb.org/manual/core/data-modeling/
链接地址: http://www.djcxy.com/p/15646.html