In mongoDB two-tier model organization of data: collection of JSON documents.
This is OK for small resources, for example, for a blog where there are only posts.
But if each user has their posts? All the posts shoved into one collection or one array? If you want to implement something more or less normal, it is necessary to write a crutch on a crutch.
Need at least a three-tier model.
var user = users.find(1);
var posts_by_user = posts.find({ user_id: user._id });
rpush user_posts:id1234 321
lrange user_posts:id1234 10 -1
rpush user_posts:id1234 321
lrange user_posts:id1234 10 -1
commented on July 9th 19 at 11:32But if each user has their posts? All the posts shoved into one collection or one array?
If you want to implement something more or less normal, it is necessary to write a crutch on a crutch.
To insert a document in a collection can only be in the end.
For example, insert the post into the collection, and I need to get posts by date.
write a crutch with skip, limit.
If you need to insert at the beginning of the collection, it would be much easier.
Prompt, please, who knows a better alternative.
Find more questions by tags DatabasesMySQLMongoDBPostgreSQLRedis