Adviced on how to array a mongodb document

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,2312312], "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!

-------------Problems Reply------------

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:

Category:codeigniter Views:0 Time:2011-10-13

Related post

  • Are arrays in MongoDB documents always kept in order? 2012-04-03

    I can find ample evidence that MongoDBs are always kept in the order given when a document is inserted or updated, but I just can't find it explicitly spelled out in the documentation for MongoDB. So I'll go ahead and ask the [probably stupid] questi

  • add property to nested array in mongodb document 2011-07-19

    I have a mongodb document with the following structure > db.user.find().limit(1); { "_id" : "1", "foo" : { "bars" : [ { "name" : "bar1" }, { "name" : "bar2" }, ], ... }, ... } I want to add a new property to each bar. I've got my script iterating

  • Search nested arrays in MongoDB documents 2012-01-18

    I am developing an web app using Codeigniter and MongoDB. Users can save their favorites sounds in as "bookmarks". Each user get one document and then each sound is appended to an array in that document called sounds. Each sound got a set of tags tha

  • Array in MongoDB Document is not loading with Java Driver 2012-03-31

    I am using MongoDB with a Java Driver. Maven ID is GroupID: org.mongodb, ArtifactId: mongo-java-driver, Version: 2.7.2. I have a collection of documents. In each document there are 2 arrays. I am loading the document like this. DBCollection products

  • Upsert Array Elements matching criteria in a MongoDB document? 2012-01-15

    As per How do I update Array Elements matching criteria in a MongoDB document? I want to upsert the array elements, so if one doesnt match then insert it, otherwise update it. I tried the answer on that question, and it works fine IF the array elemen

  • Perform case-insensitive lookup on an Array in MongoDB? 2010-05-21

    So, I've decided to get my feet wet with MongoDB and love it so far. It seems very fast and flexible which is great. But, I'm still going through the initial learning curve and as such, I'm spending hours digging for info on the most basic things. I'

  • Saving numpy array in mongodb 2011-06-16

    I have a couple of MongoDB documents wherein one my the fields is best represented as a matrix (numpy array). I would like to save this document to MongoDB, how do I do this? { 'name' : 'subject1', 'image_name' : 'blah/foo.png', 'feature1' : np.array

  • Sort data in sub array in mongodb 2011-08-23

    Is that possible to sort data in sub array in mongo database? { "_id" : ObjectId("4e3f8c7de7c7914b87d2e0eb"), "list" : [ { "id" : ObjectId("4e3f8d0be62883f70c00031c"), "datetime" : 1312787723, "comments" : { "id" : ObjectId("4e3f8d0be62883f70c00031d"

  • Select unique fields from array using MongoDB 2011-10-05

    I have a MongoDB structure which currently looks like this: [campaigns] => Array ( [0] => Array ( [campaign_id] => 4e8cba7a0b7aabea08000006 [short_code] => IHEQnP [users] => Array ( ) ) [1] => Array ( [campaign_id] => 4e8ccf7c0b7

  • how do i add a value to the top of an array in mongodb? 2011-10-28

    how do i add a value to the top of an array in mongodb? say i have this document in my mongo collection: { "colors" : [ "red", "green", "blue" ] } how do i add "yellow" to the front of the list? when i do: {$push:{colors:"yellow"}} i'd get this: { "c

  • Querying nested arrays in MongoDB & PHP 2011-11-22

    I'm using MongoDB with PHP's own driver and I have saved multiple arrays under main document. Structure looks like this: { _id: 234234234324, accounts: { 0: { enabled: 1, name: 'asdf' }, 1: { enabled: 0, name: 'gfsd' } } Accounts are removed and adde

  • Force new _id generation in embedded MongoDB documents 2011-12-05

    I am working with ASP.NET MVC 3, C# and MongoDB. I have a model with embedded documents, but I would like to auto-generate a new _id for each of my embedded documents. I can do this in the code and set Model._id = ObjectId.GenerateNewId(); But I woul

  • Reading an array in mongodb? 2012-01-22

    Hi I have some trouble with arrays in mongodb. To read a document with java is no problem but to read an array what is in a document is a problem. Lets say I have a collection myCol: {"name": "lenny linux", "gender": "m", "computers": [{"name": "comp

  • How to sort array of embedded documents via Mongoose query? 2012-02-19

    I'm building a node.js application with Mongoose and have a problem related to sorting embedded documents. Here's the schema I use: var locationSchema = new Schema({ lat: { type: String, required: true }, lon: { type: String, required: true }, time:

  • Convert SQL table to mongoDB document 2010-12-07

    What's the best way to convert a SQL database, let's say 1 table, to a mongoDB document? I guess I could use a C# driver and implement a loop, which selects each row in the table and saves that in Mongo.. However, I am looking for a better way to con

  • calculate checkbox array length using document.getElementById in javascript 2011-04-19

    I want to calculate the length of a checkbox array using document.getElementById('test') function. I have an array whose id is test and lenght I want calculating checkbox array length using document.getElementById('test') strictly. --------------Solu

  • Better design pattern for MongoDB document-object-mapper 2011-05-12

    I'm author of YiiMongoDbSuite the extension that brings MongoDB support in ActiveRecord pattern very similar to SQL one already available in core Yii. My code became quite popular, as it was written with intention to be almost identical as the origin

  • How to update nested object field in MongoDB document via Mongoose Node.js ORM? 2011-08-02

    I can't figure out how to change the value of a field in a nested document in a MongoDB document via the Mongoose Node.js JavaScript ORM. Code in CoffeeScript: mongoose = require 'mongoose' mongoose.connect 'mongodb://localhost/test' Schema = mongoos

  • How to get value from a MongoDB document 2011-11-06

    I am trying to get a value from a mongodb document, but I am not getting result even if the request is correct:, db){ var request = { 'hash' : req.params['link'] } db.collection('urlmaps', function(error, collection){ var result

Copyright (C), All Rights Reserved.

processed in 1.083 (s). 11 q(s)