Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account
List archives

Grow Document With Updates Or Make A Separate Collection

MapReduce randomly failing on same DataSet
(34 lines)
how to use $in in c++
(24 lines)
Feb 8, 2012
Brian Carpio
Brian Carpio
This might be an obvious question for some pros but I am a little bit
confused.

Lets say I am making an application lets say a "Weight Loss" app where
a user each day logs in and reports what their current weight is. It
seems there are two ways to do this one way is to just make a single
document like:

{
  _id : ObjectId("4e77bb3b8a3e000000004f7a"),
  when : Date("2011-09-19T02:10:11.3Z",
  user : "alex",
  start_date : Date("2011-10-10T02:10:11.3Z"),
  start_weight : "210",
  weight_log : [
    { weight : "209", when : Date("2011-09-20")},
    { weight : "208", when : Date("2011-09-21")},
    .....
  ]
}

Obviously as each user adds weight data to the document the document
is ever increasing which could have a very serious impact on the
actual data being used per stored document due to padding and how the
collection decided over time to pad each document. Is it ok to have
documents which vary significantly in size in the same collection. For
instance user "Bob" might only track his weight once a month, where as
user "Alex" might track his weight every day. Over the course of a
year "Bob" would have 12 weight_logs where "Alex" could have
hundreds.

The other way I was thinking about this would be to make two
collections one "users" and the other "weight log", each weight log
document would have the user name (or some other id) and the date and
weight... My concern about this approach is that this collection could
be huge depending on the number of users utilizing the system.

What is the proper or "best" MongoDB way?





Reply
Tags: two wayslittle bitlogsweight loss
Messages in this thread
Grow Document With Updates Or Make A Separate Collection
set --logappend , make the log file grow more and more larger
December 15, 2011 10:32:18 PM
I use --logappend in my mongod config.it can record all my db log. And the log file grow more and more larger.now my db log has more than 154M. I can't use a normal editor view the log because the log file is too lage. How can i do? and if the db…
Help with collection design and updates with Perl
January 17, 2012 06:57:08 AM
Greetings, I'm new to MongoDB. I'm exploring using MongoDB to store information from a job scheduler. Jobs have unique names and can run on multiple hosts. Each job has three possible statuses: finished, running and failed. Stored with each…
updates document question
May 30, 2011 01:26:12 PM
Sorry, I am a complete newbie in couchdb. I am in update function function(doc, req) { doc.att = other_doc.att return [doc, "updated doc"]; } How I can get other_doc in my update function? http://diglossa.org…
Iterating over a large collection while writing updates to another
December 13, 2011 01:39:22 PM
Hi, I have a problem where I need to iterate over a collection A, decently big in size, and for each object I need to write updates to a corresponding object in another collection B. The writes are slow and eventually the cursor over the…
Document Updates handler using POST instead of PUT
December 11, 2010 12:13:38 PM
I'm following the wiki guide for document updates here: http://wiki.apache.org/couchdb/Document_Update_Handlers I created an update handler _design doc called "active_test", which will update the active_test value in my document and looks like…
About document updates and disk offset
August 10, 2011 07:17:05 AM
Hi, I've been reading this: http://www.mongodb.org/display/DOCS/Excessive+Disk+Space And after trying to browse MongoDB source code and I'm under the impression that updates are actually implemented as a combination of removal plus…
Improve performance of lots of updates in a large collection
October 31, 2011 01:47:54 PM
Hi there, I noticed, that updating a lot of entries (or creating a lot of entries) in a collections takes considerable time. I'm looking for ways to improve this. I have a collection with over 10Mio documents. I would like to update a large…
multiple updates inside array in a document
November 8, 2010 04:56:48 PM
Hi, having this document design posts > db.posts.findOne(); { "_id" : ObjectId("4cd2e15b150ba0132e010000"), "comments" : [ { "_id" : ObjectId("4cd2e15b150ba0132e000000"), …
Moving a document to a new collection
April 18, 2011 02:14:21 AM
Hi I'm porting my database from SQL Server to MongoDB that supports a user published story website. I am going to create a collection called stories, within that there will be 3 sub collections, stories.draft, stories.unverified and…
a way to check if a document exists in a collection?
October 24, 2010 07:17:17 PM
Hey, I'm trying to figure out the best way (regarding performance) to check if a document with a certain _id exists in a collection. I know i can just query for it, but that doesn't seem too efficient. I guess my question is this: if i do…
Proposed document/collection structure
November 7, 2011 09:45:22 PM
Hi, We are planning a new web application that has a set of requirements and I would like some advice/opinions of a good way to implement this in MongoDB (or even opinion that it may not be suitable) The application needs to handle "Uploads" of…
Validating if document is present in the collection
November 30, 2011 04:01:41 AM
What is the better way (I'm using the C# official driver): bool Exists(ObjectId id) { var query = Query.EQ("_id", id); return _coll.Find(query).Any(); } or bool Exists(ObjectId id) { return _coll.FindOneById(id) != null; }
Copy and Insert a document on Same collection
November 27, 2011 12:18:34 AM
Hi, Can anyone help me to copy and insert a document in same collection. I tried following on mongo command shell. but it gives me an error. the reason is the same mongo _id. the whole document is going to copy including mongo _id. following is…
document size and num of docs in a capped collection
March 29, 2011 11:56:33 AM
I am using a ruby on rails with a gem called central_logger. For some reason whenever that logger inserts a document, it seems as if the document has a hidden buffer that I can't see which affects the number of documents my (sized) capped…
C# Offical Driver] How to get the id of a new document insert to collection
December 2, 2011 01:09:08 AM
When I insert a document to the collection,I can't get the id which is create by idGenerator.... SafeModeResult is not contains new id.....
why newly inserted document in the collection appearing at the top
May 30, 2011 04:48:28 PM
I have a lookup collection for countries. This collection has just one field _id which stores the country names. countries: { _id: "Afganistan", _id: "Albania", _id: "Algeria", .... } I need to store the countries alphabetically sorted in the…
Updating a document in an embedded collection with the official C# driver
December 7, 2010 09:16:52 AM
If I have a Company collection which contains embedded Divisions: { "_id": 1 "_t": "Company", "Name": "Test Company" "Divisions": [ { "_id": 1 "_t": "Division", "Name": "Test Division 1" }, { "_id":…
How to do a multi-location search of a single document instead a whole collection?
April 4, 2011 07:47:35 AM
I have multiple locations, each have locations of their own to which I'm trying to determine the maximum distance of that document. Geospatial indexes seems to be the best solution.
My update with $push just reordered the document fields in my collection. How bad is this?
April 12, 2011 06:05:47 PM
I just gave an update command against one doc in my collection. After the update, I wanted to check the document. Now I see the fields are alphabetically sorted. As per documentation on mongo site it might happen. Fine. But other docs still have…
How to make partial updates from json data with the official C# driver
January 7, 2012 01:48:16 AM
Hi I want to make a general method to do PARTIAL updates of a document from json data. The json data contiains a subset of the fields of the POCO being updated. I have this: public static void Update(MongoCollection collection, ObjectId…
Automatic document updates in couchdb
May 13, 2011
I have 10,000+ couchdb documents, each having (simplified) format like - { "First Name" : "John", "Last Name" : "Doe" } I want to add another field…
Document updates using mongo-ruby-driver?
January 22, 2011
Assuming the following: irb> x irb> => {"_id"=> 123456, "welcome"=>"Hi!", "welcome2" => "Enjoy your stay!"} irb> coll.class…
Use save() to update an existing document in a collection
January 1, 2011
Hi, everybody. I love manga. And now I am learning to love mongo too :-) There is an explanation of how to use save() to update an existing document…
Adding new property to each document in a large collection
May 31, 2011
Using the mongodb shell, I'm trying to add a new property to each document in a large collection. The collection (Listing) has an existing property…
MongoDB, return recent document for each user_id in collection
February 28, 2011
Looking for similar functionality to Postgres' Distinct On. Have a collection of documents {user_id, current_status, date}, where status is just…
How do I sort a MongoDB collection by a field in an embedded document using Mongoid?
March 1, 2011
I want to run this query using Mongoid: db.users.find().sort({'users.roles.name':1}) What will that look like in Mongoid? Or maybe there is an easy…
How to query a collection of embedded mongo documents to extract specific document with a list of criteria?
May 4, 2011
I am trying to select a collection of document based on the content of their embedded documents. My model looks like this: class box embeds_many…
How do I make this only appear on the first page? And how do I separate two cells?
March 21, 2011
This code pretty much just shows a a table with 16 cells (4 columns and 4 rows). Except on the top right, there are two "RESERVED" cells. This code…
How to make preg_match to find whole word but not separate hyphen-words?
April 25, 2011
if (preg_match('#\b'.$rawword.'\b#i',$body)) { This code finds whole words, but if they are a hyphen word like "ABLE-BODIED" it will find ABLE and…
How do I make apache load different document roots for different ports?
March 11, 2011
I want apache to do this > mydomain.com:80 --- opens var/www1 mydomain.com:81 --- opens var/ww2 mydomain.com:82 --- opens var/www3 Problem is I…
How do I make a RTF (Rich Text Format) document through PHP from a form submission?
June 7, 2011
I'm searching on Google but most of the results I'm getting have these complicated software being used. I'm choosing to use RTF because it's the…
MySQL table updates, but not fast enough for a select statement on the same page to access the updates - any ideas?
February 18, 2011
I am trying to write some code that updates a mysql table, and then selects out of that same table in the same page. However, I find that when I do…
Android SQL Lite fail to grow
December 30, 2010
We are creating a app that syncs 5000 calendar entries with the server. Issue is that after adding 1913 entries it failing. And giving the following…
Mysql 5.1 temp files grow problem on Ububntu
March 31, 2011
Hi, Recently moved database server from old Gentoo environment with mysql5.0 to Ubuntu 10.04.2 LTS with MySQL 5.1.41. And noticed really weird…
Mysql sequential updates or simultaneous updates
March 5, 2011
Hello, I would like to ask, whether it is more optimum to perform a simultaneous update in 3 mysql tables using a joined query or perform each in…
MongoID query for a collection that references a collection that references a collection
February 6, 2011
Hi everyone, I have a User model, a Workout model and a Exercise model. I am using Devise for user management and MongoID to interact with MongoDB.…
Handling custom user fields with possibility of grow and shrink.
March 2, 2011
Hi, This question is much about How to do, idea etc. I have a situation where user can create as many custom fields as he can of type…
Each status update in Facebook inserts a new row in table or updates a field containing a list/CSV of status updates?
February 1, 2011
analyzing Facebook. When a user posts something on his wall.. these updates are stored in newly inserted different rows or newly added different…
How to force a Doctrine MongoDB ODM Document Proxy to convert to the 'original' document?
June 8, 2011
I have a document Person referenced in document User. When I retrieve User, it doesn't have a Person object embedded, but a Person proxy object. Is…
Rails and mongoid: Validation is called on the referenced document upon saving/updating the referrer document ??
March 3, 2011
I have a model Tracker that references_many Users . Everything works fine, but for some business reasons, sometimes my Users model are in a…