Using the value of a MongoDB field to update another field
<p>I have a MongoDB document with a structure like this:</p>

<pre><code>{
    testValue: 10,
    maxValue: 20
}
</code></pre>

<p>I want to set <code>testValue</code> to an arbitrary integer value between 0 and <code>maxValue</code>. Ideally, I would do something like this:</p>

<pre><code>db.collection.update(
    {},
    {
        $set: { 'testValue': newValue },
        $min: { 'testValue': 0 },
        $max: { 'textValue': $maxValue }
    }
)
</code></pre>

<p>But that obviously doesn't work. There are a handful of threads that relate to this question (e.g. <a href="https://stackoverflow.com/questions/3974985/update-mongodb-field-using-value-of-another-field">Update MongoDB field using value of another field</a>), but they're all a few years old, and I can't find pertinent information in the official documentation. Is there a way to do what I want, or do I have to use find() to get <code>maxValue</code> then do a separate call to the database using update()?</p>