Skip to content

Commit

Permalink
chore: update opencollective sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 8, 2024
1 parent 36f0408 commit 3aadc60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/api/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ <h4 id="callback-signature">
<span class="method-type">&laquo;Boolean&raquo;</span> If set to <code>true</code>, translates any schema-defined aliases in <code>filter</code>, <code>projection</code>, <code>update</code>, and <code>distinct</code>. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteDiscriminatorKey=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes discriminator key updates from <code>update</code> by default, set <code>overwriteDiscriminatorKey</code> to <code>true</code> to allow updating the discriminator key</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteImmutable=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes updated immutable properties from <code>update</code> by default (excluding $setOnInsert). Set <code>overwriteImmutable</code> to <code>true</code> to allow updating immutable properties using other update operators.</p>
</li></ul></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;Query&raquo;</span> this</li></ul><h5>See:</h5><ul><li><span class="method-type"><a href="/docs/tutorials/findoneandupdate.html">Tutorial</a></span></li><li><span class="method-type"><a href="https://www.mongodb.com/docs/manual/reference/command/findAndModify/">findAndModify command</a></span></li><li><span class="method-type"><a href="https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html">ModifyResult</a></span></li><li><span class="method-type"><a href="https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#findOneAndUpdate">findOneAndUpdate</a></span></li></ul><div><p>Issues a mongodb <code>findOneAndUpdate()</code> command.</p>
<p>Finds a matching document, updates it according to the <code>update</code> arg, passing any <code>options</code>, and returns the found
document (if any).</p>
Expand Down Expand Up @@ -1361,6 +1363,7 @@ <h4 id="options">
<li><a href="https://www.mongodb.com/docs/manual/reference/method/db.collection.update/">writeConcern</a></li>
<li><a href="/docs/guide.html#timestamps">timestamps</a>: If <code>timestamps</code> is set in the schema, set this option to <code>false</code> to skip timestamps for that particular update. Has no effect if <code>timestamps</code> is not enabled in the schema options.</li>
<li>overwriteDiscriminatorKey: allow setting the discriminator key in the update. Will use the correct discriminator schema if the update changes the discriminator key.</li>
<li>overwriteImmutable: allow overwriting properties that are set to <code>immutable</code> in the schema. Defaults to false.</li>
</ul>
<p>The following options are only for <code>find()</code>, <code>findOne()</code>, <code>findById()</code>, <code>findOneAndUpdate()</code>, <code>findOneAndReplace()</code>, <code>findOneAndDelete()</code>, and <code>findByIdAndUpdate()</code>:</p>
<ul>
Expand Down Expand Up @@ -1575,6 +1578,8 @@ <h4 id="example">
<span class="method-type">&laquo;Boolean&raquo;</span> If set to <code>true</code>, translates any schema-defined aliases in <code>filter</code>, <code>projection</code>, <code>update</code>, and <code>distinct</code>. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteDiscriminatorKey=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes discriminator key updates from <code>update</code> by default, set <code>overwriteDiscriminatorKey</code> to <code>true</code> to allow updating the discriminator key</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteImmutable=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes updated immutable properties from <code>update</code> by default (excluding $setOnInsert). Set <code>overwriteImmutable</code> to <code>true</code> to allow updating immutable properties using other update operators.</p>
</li></ul><li class="param"><code>[callback]</code>
<span class="method-type">&laquo;Function&raquo;</span> params are (error, writeOpResult)</p>
</li></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;Query&raquo;</span> this</li></ul><h5>See:</h5><ul><li><span class="method-type"><a href="/docs/api/model.html#Model.update()">Model.update</a></span></li><li><span class="method-type"><a href="/docs/queries.html">Query docs</a></span></li><li><span class="method-type"><a href="https://www.mongodb.com/docs/manual/reference/method/db.collection.update/">update</a></span></li><li><span class="method-type"><a href="https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html">UpdateResult</a></span></li><li><span class="method-type"><a href="https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output">MongoDB docs</a></span></li></ul><div><p>Declare and/or execute this query as an updateMany() operation.
Expand Down Expand Up @@ -1610,6 +1615,8 @@ <h4 id="example">
<span class="method-type">&laquo;Boolean&raquo;</span> If set to <code>true</code>, translates any schema-defined aliases in <code>filter</code>, <code>projection</code>, <code>update</code>, and <code>distinct</code>. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteDiscriminatorKey=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes discriminator key updates from <code>update</code> by default, set <code>overwriteDiscriminatorKey</code> to <code>true</code> to allow updating the discriminator key</p>
</li></ul><ul style="margin-top: 0.5em"><li><code>[options.overwriteImmutable=false]</code>
<span class="method-type">&laquo;Boolean&raquo;</span> Mongoose removes updated immutable properties from <code>update</code> by default (excluding $setOnInsert). Set <code>overwriteImmutable</code> to <code>true</code> to allow updating immutable properties using other update operators.</p>
</li></ul><li class="param"><code>[callback]</code>
<span class="method-type">&laquo;Function&raquo;</span> params are (error, writeOpResult)</p>
</li></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;Query&raquo;</span> this</li></ul><h5>See:</h5><ul><li><span class="method-type"><a href="/docs/api/model.html#Model.update()">Model.update</a></span></li><li><span class="method-type"><a href="/docs/queries.html">Query docs</a></span></li><li><span class="method-type"><a href="https://www.mongodb.com/docs/manual/reference/method/db.collection.update/">update</a></span></li><li><span class="method-type"><a href="https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html">UpdateResult</a></span></li><li><span class="method-type"><a href="https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output">MongoDB docs</a></span></li></ul><div><p>Declare and/or execute this query as an updateOne() operation.
Expand Down
18 changes: 17 additions & 1 deletion docs/timestamps.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,20 @@
So, for example, if you want to <em>only</em> set <code>updatedAt</code> if a new document is created, you can disable the <code>updatedAt</code> timestamp and set it yourself as shown below:</p>
<pre><code lang="javascript"><span class="hljs-keyword">await</span> <span class="hljs-title class_">User</span>.<span class="hljs-title function_">findOneAndUpdate</span>({}, { <span class="hljs-attr">$setOnInsert</span>: { <span class="hljs-attr">updatedAt</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>() } }, {
<span class="hljs-attr">timestamps</span>: { <span class="hljs-attr">createdAt</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">updatedAt</span>: <span class="hljs-literal">false</span> }
});</code></pre></div></div><div id="jobs"><div class="job-listing"><a href="/docs/jobs.html#61f0b0402d893554bc3a247f"><div class="company-logo"><img src="https://assets.localizecdn.com/uploads/1689251999716.png"></div><div class="description"><div class="company">Localize</div><div class="title">Full Stack Engineer</div><div class="location">Anywhere</div></div></a></div><div class="button jobs-view-more"><a href="/docs/jobs.html">View more jobs!</a></div></div><script type="text/javascript" src="/docs/js/navbar-search.js"></script><script type="text/javascript" src="/docs/js/mobile-navbar-toggle.js"></script></div></body></html>
});</code></pre><h2 id="updating-timestamps">
<a href="#updating-timestamps">
Updating Timestamps
</a>
</h2>
<p>If you need to disable Mongoose&#39;s timestamps and update a document&#39;s timestamps to a different value using <code>updateOne()</code> or <code>findOneAndUpdate()</code>, you need to do the following:</p>
<ol>
<li>Set the <code>timestamps</code> option to <code>false</code> to prevent Mongoose from setting <code>updatedAt</code>.</li>
<li>Set <code>overwriteImmutable</code> to <code>true</code> to allow overwriting <code>createdAt</code>, which is an immutable property by default.</li>
</ol>
<pre><code lang="javascript"><span class="hljs-keyword">const</span> createdAt = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>(<span class="hljs-string">&#x27;2011-06-01&#x27;</span>);
<span class="hljs-comment">// Update a document&#x27;s `createdAt` to a custom value.</span>
<span class="hljs-comment">// Normally Mongoose would prevent doing this because `createdAt` is immutable.</span>
<span class="hljs-keyword">await</span> <span class="hljs-title class_">Model</span>.<span class="hljs-title function_">updateOne</span>({ <span class="hljs-attr">_id</span>: doc.<span class="hljs-property">_id</span> }, { createdAt }, { <span class="hljs-attr">overwriteImmutable</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">timestamps</span>: <span class="hljs-literal">false</span> });

doc = <span class="hljs-keyword">await</span> <span class="hljs-title class_">Model</span>.<span class="hljs-property">collection</span>.<span class="hljs-title function_">findOne</span>({ <span class="hljs-attr">_id</span>: doc.<span class="hljs-property">_id</span> });
doc.<span class="hljs-property">createdAt</span>.<span class="hljs-title function_">valueOf</span>() === createdAt.<span class="hljs-title function_">valueOf</span>(); <span class="hljs-comment">// true</span></code></pre></div></div><div id="jobs"><div class="job-listing"><a href="/docs/jobs.html#61f0b0402d893554bc3a247f"><div class="company-logo"><img src="https://assets.localizecdn.com/uploads/1689251999716.png"></div><div class="description"><div class="company">Localize</div><div class="title">Full Stack Engineer</div><div class="location">Anywhere</div></div></a></div><div class="button jobs-view-more"><a href="/docs/jobs.html">View more jobs!</a></div></div><script type="text/javascript" src="/docs/js/navbar-search.js"></script><script type="text/javascript" src="/docs/js/mobile-navbar-toggle.js"></script></div></body></html>
Loading

0 comments on commit 3aadc60

Please sign in to comment.