title: Maintaining order of mongodb collection
body: <p>I have a collection that will have many documents (maybe millions). When a user inserts a new document, I would like to have a field that maintains the "order" of the data that I can index. For example, if one field is time, in this format "1352392957.46516", if I have three documents, the first with time: 1352392957.46516 and the second with time: 1352392957.48516 (20ms later) and the third with 1352392957.49516 (10ms later) I would like to have an another field where the first document would have 0, and the second would be 1, the third 2 and so on.</p>
  
  <p>The reason I want this is so that I can index that field, then when I do a find I can do an efficient $mod operation to down sample the data. So for example, if I have a million docs, and I only want 1000 of them evenly spaced, I could do a  $mod [1000, 0] on the integer field.</p>
  
  <p>The reason I could not do that on the Time field is because they may not be perfectly spaced, or might be all even or odd so the mod would not work. So the separate integer field would keep the order in a linearly increasing fashion.</p>
  
  <p>Also, you should be able to insert documents anywhere in the collection, so all subsequent fields would need to be updated.</p>
  
  <p>Is there a way to do this automatically? Or would I have to implement this? Or is there a more efficient way of doing what I am describing?</p>