开发者

Adviced on how to array a mongodb document

开发者 https://www.devze.com 2023-04-13 06:30 出处:网络
I am building an API using Codeigniter and MongoDB. I got some questions about how to \"model\" the mongoDB.

I am building an API using Codeigniter and MongoDB. I got some questions about how to "model" the mongoDB.

A user should have basic data like name and user should also be able to follow other users. Like it is now each user document keeps track of all people that is following him and all that he is following. This is done by using arrays of user _ids.

Like this:

"following": [323424,2323123,231231开发者_JAVA百科2],
"followers": [355656,5656565,5656234234,23424243,234246456],
"fullname": "James Bond"

Is this a good way? Perhaps the user document should only contain ids of peoples that the user is following and not who is following him? I can imaging that keeping potentially thousands of ids (for followers) in an array will make the document to big?

All input is welcome!


The max-document size is currently limited to 16MB (v1.8.x and up), this is pretty big. But i still think, that it would be ok in this case to move the follower-relations to an own collection -- you never know how big your project gets.

However: i would recommend using database references for storing the follower-relations: it's way easier to resolve the user from a database reference. Have a look at:

http://www.mongodb.org/display/DOCS/Database+References

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号