Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB MapReduce update in place how to
    primarykey
    data
    text
    <p>*Basically I'm trying to order objects by their score over the last hour.</p> <p>I'm trying to generate an hourly votes sum for objects in my database. Votes are embedded into each object. The object schema looks like this:</p> <pre><code>{ _id: ObjectId score: int hourly-score: int &lt;- need to update this value so I can order by it recently-voted: boolean votes: { "4e4634821dff6f103c040000": { &lt;- Key is __toString of voter ObjectId "_id": ObjectId("4e4634821dff6f103c040000"), &lt;- Voter ObjectId "a": 1, &lt;- Vote amount "ca": ISODate("2011-08-16T00:01:34.975Z"), &lt;- Created at MongoDate "ts": 1313452894 &lt;- Created at timestamp }, ... repeat ... } } </code></pre> <p>This question is actually related to a question I asked a couple of days ago <a href="https://stackoverflow.com/questions/7046462/best-way-to-model-a-voting-system-in-mongodb">Best way to model a voting system in MongoDB</a></p> <p>How would I (can I?) run a MapReduce command to do the following:</p> <ol> <li>Only run on objects with recently-voted = true OR hourly-score > 0.</li> <li>Calculate the sum of the votes created in the last hour.</li> <li>Update hourly-score = the sum calculated above, and recently-voted = false.</li> </ol> <p>I also read <a href="http://blog.boxedice.com/2010/06/21/map-reduce-and-mongodb/" rel="nofollow noreferrer">here</a> that I can perform a MapReduce on the slave DB by running db.getMongo().setSlaveOk() before the M/R command. Could I run the reduce on a slave and update the master DB?</p> <p>Are in-place updates even possible with Mongo MapReduce?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload