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 Aug 12, 2024
1 parent 2c9b6a6 commit 674f782
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 14 deletions.
8 changes: 8 additions & 0 deletions docs/api/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
</div><hr class="separate-api-elements"><h3 id="MongooseMap.prototype.set()"><a href="#MongooseMap.prototype.set()"><code>MongooseMap.prototype.set()</code></a></h3><div><p>Overwrites native Map&#39;s <code>set()</code> function to support setters, <code>populate()</code>,
and change tracking. Note that Mongoose maps <em>only</em> support strings and
ObjectIds as keys.</p>
<p>Keys also cannot:</p>
<ul>
<li>be named after special properties <code>prototype</code>, <code>constructor</code>, and <code>__proto__</code></li>
<li>start with a dollar sign (<code>$</code>)</li>
<li>contain any dots (<code>.</code>)</li>
</ul>
<h4 id="example">Example:</h4>
<pre><code>doc.myMap.set(&#39;test&#39;, 42); // works
doc.myMap.set({ obj: 42 }, 42); // Throws &quot;Mongoose maps only support string keys&quot;
doc.myMap.set(10, 42); // Throws &quot;Mongoose maps only support string keys&quot;
doc.myMap.set(&quot;$test&quot;, 42); // Throws &quot;Mongoose maps do not support keys that start with &quot;$&quot;, got &quot;$test&quot;&quot;
</code></pre>
</div><hr class="separate-api-elements"><h3 id="MongooseMap.prototype.toBSON()"><a href="#MongooseMap.prototype.toBSON()"><code>MongooseMap.prototype.toBSON()</code></a></h3><div><p>Converts this map to a native JavaScript Map so the MongoDB driver can serialize it.</p>
</div><hr class="separate-api-elements"><h3 id="MongooseMap.prototype.toJSON()"><a href="#MongooseMap.prototype.toJSON()"><code>MongooseMap.prototype.toJSON()</code></a></h3><h5>Parameters:</h5><ul class="params"><li class="param"><code>[options]</code>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/schematype.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ <h4 id="example">Example:</h4>
<p>Suppose you are implementing user registration for a website. Users provide
an email and password, which gets saved to mongodb. The email is a string
that you will want to normalize to lower case, in order to avoid one email
having more than one account -- e.g., otherwise, <a href="mailto:&#97;&#x76;&#x65;&#110;&#117;&#101;&#x40;&#113;&#46;&#99;&#111;&#x6d;">&#97;&#x76;&#x65;&#110;&#117;&#101;&#x40;&#113;&#46;&#99;&#111;&#x6d;</a> can be registered for 2 accounts via <a href="mailto:&#x61;&#x76;&#x65;&#110;&#117;&#x65;&#64;&#113;&#46;&#99;&#111;&#x6d;">&#x61;&#x76;&#x65;&#110;&#117;&#x65;&#64;&#113;&#46;&#99;&#111;&#x6d;</a> and <a href="mailto:&#x41;&#x76;&#x45;&#110;&#x55;&#x65;&#x40;&#81;&#x2e;&#67;&#111;&#77;">&#x41;&#x76;&#x45;&#110;&#x55;&#x65;&#x40;&#81;&#x2e;&#67;&#111;&#77;</a>.</p>
having more than one account -- e.g., otherwise, <a href="mailto:&#97;&#118;&#x65;&#110;&#x75;&#x65;&#x40;&#113;&#46;&#99;&#x6f;&#x6d;">&#97;&#118;&#x65;&#110;&#x75;&#x65;&#x40;&#113;&#46;&#99;&#x6f;&#x6d;</a> can be registered for 2 accounts via <a href="mailto:&#x61;&#x76;&#101;&#x6e;&#x75;&#101;&#x40;&#113;&#46;&#x63;&#111;&#109;">&#x61;&#x76;&#101;&#x6e;&#x75;&#101;&#x40;&#113;&#46;&#x63;&#111;&#109;</a> and <a href="mailto:&#65;&#x76;&#69;&#x6e;&#85;&#x65;&#64;&#x51;&#46;&#67;&#x6f;&#x4d;">&#65;&#x76;&#69;&#x6e;&#85;&#x65;&#64;&#x51;&#46;&#67;&#x6f;&#x4d;</a>.</p>
<p>You can set up email lower case normalization easily via a Mongoose setter.</p>
<pre><code>function toLower(v) {
return v.toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion docs/queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2 id="streaming"><a href="#streaming">Streaming</a></h2>
</code></pre>
<p>Iterating through a Mongoose query using <a href="https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js.html">async iterators</a>
also creates a cursor.</p>
<pre><code class="language-javascript"><span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> doc <span class="hljs-keyword">of</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">find</span>()) {
<pre><code class="language-javascript"><span class="hljs-keyword">for</span> <span class="hljs-title function_">await</span> (<span class="hljs-keyword">const</span> doc <span class="hljs-keyword">of</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">find</span>()) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(doc); <span class="hljs-comment">// Prints documents one at a time</span>
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/getters-setters.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2 id="getters">Getters</h2>
user.<span class="hljs-property">email</span>; <span class="hljs-comment">// **@gmail.com</span>
</code></pre>
<p>Keep in mind that getters do <strong>not</strong> impact the underlying data stored in
MongoDB. If you save <code>user</code>, the <code>email</code> property will be &#39;<a href="mailto:&#97;&#98;&#x40;&#x67;&#109;&#x61;&#x69;&#x6c;&#x2e;&#99;&#111;&#109;">&#97;&#98;&#x40;&#x67;&#109;&#x61;&#x69;&#x6c;&#x2e;&#99;&#111;&#109;</a>&#39; in
MongoDB. If you save <code>user</code>, the <code>email</code> property will be &#39;<a href="mailto:&#x61;&#98;&#x40;&#103;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#x63;&#111;&#109;">&#x61;&#98;&#x40;&#103;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#x63;&#111;&#109;</a>&#39; in
the database.</p>
<p>By default, Mongoose does <strong>not</strong> execute getters when converting a document to JSON, including <a href="http://expressjs.com/en/4x/api.html#res.json">Express&#39; <code>res.json()</code> function</a>.</p>
<pre><code class="language-javascript">app.<span class="hljs-title function_">get</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">req, res</span>) {
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/virtuals.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<h2 id="your-first-virtual">Your First Virtual</h2>
<p>Suppose you have a <code>User</code> model. Every user has an <code>email</code>, but you also
want the email&#39;s domain. For example, the domain portion of
&#39;<a href="mailto:&#116;&#101;&#x73;&#x74;&#64;&#x67;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#99;&#111;&#109;">&#116;&#101;&#x73;&#x74;&#64;&#x67;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#99;&#111;&#109;</a>&#39; is &#39;gmail.com&#39;.</p>
&#39;<a href="mailto:&#116;&#101;&#x73;&#x74;&#x40;&#103;&#x6d;&#x61;&#105;&#108;&#46;&#99;&#x6f;&#109;">&#116;&#101;&#x73;&#x74;&#x40;&#103;&#x6d;&#x61;&#105;&#108;&#46;&#99;&#x6f;&#109;</a>&#39; is &#39;gmail.com&#39;.</p>
<p>Below is one way to implement the <code>domain</code> property using a virtual.
You define virtuals on a schema using the <a href="../api/schema.html#schema_Schema-virtual"><code>Schema#virtual()</code> function</a>.</p>
<pre><code class="language-javascript"><span class="hljs-keyword">const</span> userSchema = mongoose.<span class="hljs-title class_">Schema</span>({
Expand Down
2 changes: 1 addition & 1 deletion docs/typescript/populate.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2 id="using-populateddoc">Using <code>PopulatedDoc</code></h2>
<span class="hljs-keyword">const</span> <span class="hljs-attr">childSchema</span>: <span class="hljs-title class_">Schema</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Schema</span>({ <span class="hljs-attr">name</span>: <span class="hljs-title class_">String</span> });
<span class="hljs-keyword">const</span> <span class="hljs-title class_">ChildModel</span> = model&lt;<span class="hljs-title class_">Child</span>&gt;(<span class="hljs-string">&#x27;Child&#x27;</span>, childSchema);

<span class="hljs-title class_">ParentModel</span>.<span class="hljs-title function_">findOne</span>({}).<span class="hljs-title function_">populate</span>(<span class="hljs-string">&#x27;child&#x27;</span>).<span class="hljs-title function_">orFail</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">doc: Parent</span>) =&gt;</span> {
<span class="hljs-title class_">ParentModel</span>.<span class="hljs-title function_">findOne</span>({}).<span class="hljs-title function_">populate</span>(<span class="hljs-string">&#x27;child&#x27;</span>).<span class="hljs-title function_">orFail</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params"><span class="hljs-attr">doc</span>: <span class="hljs-title class_">Parent</span></span>) =&gt;</span> {
<span class="hljs-keyword">const</span> child = doc.<span class="hljs-property">child</span>;
<span class="hljs-keyword">if</span> (child == <span class="hljs-literal">null</span> || child <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">ObjectId</span>) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">&#x27;should be populated&#x27;</span>);
Expand Down
6 changes: 3 additions & 3 deletions docs/typescript/query-helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ <h2 id="manually-typed-query-helpers">Manually Typed Query Helpers</h2>
});

<span class="hljs-title class_">ProjectSchema</span>.<span class="hljs-property">query</span>.<span class="hljs-property">byName</span> = <span class="hljs-keyword">function</span> <span class="hljs-title function_">byName</span>(<span class="hljs-params">
<span class="hljs-variable language_">this</span>: QueryWithHelpers&lt;<span class="hljs-built_in">any</span>, HydratedDocument&lt;Project&gt;, ProjectQueryHelpers&gt;,
name: <span class="hljs-built_in">string</span>
<span class="hljs-attr">this</span>: <span class="hljs-title class_">QueryWithHelpers</span>&lt;<span class="hljs-built_in">any</span>, <span class="hljs-title class_">HydratedDocument</span>&lt;<span class="hljs-title class_">Project</span>&gt;, <span class="hljs-title class_">ProjectQueryHelpers</span>&gt;,
<span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span>
</span>) {
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">find</span>({ <span class="hljs-attr">name</span>: name });
};
Expand All @@ -86,7 +86,7 @@ <h2 id="auto-typed-query-helpers">Auto Typed Query Helpers</h2>
<span class="hljs-attr">stars</span>: <span class="hljs-title class_">Number</span>
}, {
<span class="hljs-attr">query</span>: {
<span class="hljs-title function_">byName</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-title function_">byName</span>(<span class="hljs-params"><span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">find</span>({ name });
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/typescript/schemas.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h2 id="automatic-type-inference">Automatic type inference</h2>
<li>You need to define your schema in the <code>new Schema()</code> call. Don&#39;t assign your schema definition to a temporary variable. Doing something like <code>const schemaDefinition = { name: String }; const schema = new Schema(schemaDefinition);</code> will not work.</li>
<li>Mongoose adds <code>createdAt</code> and <code>updatedAt</code> to your schema if you specify the <code>timestamps</code> option in your schema, <em>except</em> if you also specify <code>methods</code>, <code>virtuals</code>, or <code>statics</code>. There is a <a href="https://github.com/Automattic/mongoose/issues/12807">known issue</a> with type inference with timestamps and methods/virtuals/statics options. If you use methods, virtuals, and statics, you&#39;re responsible for adding <code>createdAt</code> and <code>updatedAt</code> to your schema definition.</li>
</ol>
<p>If you must define your schema separately, use <a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions">as const</a> (<code>const schemaDefinition = { ... } as const;</code>) to prevent <em>type widening</em>. TypeScript will automatically widen types like <code>required: false</code> to <code>required: boolean</code>, which will cause Mongoose to assume the field is required. Using <code>as const</code> forces TypeScript to retain these types.</p>
<p>If you need to explicitly get the raw document type (the value returned from <code>doc.toObject()</code>, <code>await Model.findOne().lean()</code>, etc.) from your schema definition, you can use Mongoose&#39;s <code>inferRawDocType</code> helper as follows:</p>
<pre><code class="language-ts"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">Schema</span>, <span class="hljs-title class_">InferRawDocType</span>, model } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;mongoose&#x27;</span>;

Expand All @@ -52,7 +53,7 @@ <h2 id="automatic-type-inference">Automatic type inference</h2>

<span class="hljs-title function_">useRawDoc</span>(doc.<span class="hljs-title function_">toObject</span>());

<span class="hljs-keyword">function</span> <span class="hljs-title function_">useRawDoc</span>(<span class="hljs-params">doc: RawUserDocument</span>) {
<span class="hljs-keyword">function</span> <span class="hljs-title function_">useRawDoc</span>(<span class="hljs-params"><span class="hljs-attr">doc</span>: <span class="hljs-title class_">RawUserDocument</span></span>) {
<span class="hljs-comment">// ...</span>
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/typescript/statics-and-methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h2 id="both-methods-and-statics">Both Methods and Statics</h2>
<span class="hljs-attr">firstName</span>: { <span class="hljs-attr">type</span>: <span class="hljs-title class_">String</span>, <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span> },
<span class="hljs-attr">lastName</span>: { <span class="hljs-attr">type</span>: <span class="hljs-title class_">String</span>, <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span> }
});
schema.<span class="hljs-title function_">static</span>(<span class="hljs-string">&#x27;createWithFullName&#x27;</span>, <span class="hljs-keyword">function</span> <span class="hljs-title function_">createWithFullName</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span></span>) {
schema.<span class="hljs-title function_">static</span>(<span class="hljs-string">&#x27;createWithFullName&#x27;</span>, <span class="hljs-keyword">function</span> <span class="hljs-title function_">createWithFullName</span>(<span class="hljs-params"><span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-keyword">const</span> [firstName, lastName] = name.<span class="hljs-title function_">split</span>(<span class="hljs-string">&#x27; &#x27;</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">create</span>({ firstName, lastName });
});
Expand Down
4 changes: 2 additions & 2 deletions docs/typescript/statics.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
{ <span class="hljs-attr">name</span>: { <span class="hljs-attr">type</span>: <span class="hljs-title class_">String</span>, <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span> } },
{
<span class="hljs-attr">methods</span>: {
<span class="hljs-title function_">updateName</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-title function_">updateName</span>(<span class="hljs-params"><span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span> = name;
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">save</span>();
}
},
<span class="hljs-attr">statics</span>: {
<span class="hljs-title function_">createWithName</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-title function_">createWithName</span>(<span class="hljs-params"><span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span></span>) {
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">create</span>({ name });
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/validation.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ <h2 id="required-validators-on-nested-objects">Required Validators On Nested Obj

assert.<span class="hljs-title function_">throws</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// This throws an error, because &#x27;name&#x27; isn&#x27;t a full fledged path</span>
personSchema.<span class="hljs-title function_">path</span>(<span class="hljs-string">&#x27;name&#x27;</span>).required(<span class="hljs-literal">true</span>);
personSchema.<span class="hljs-title function_">path</span>(<span class="hljs-string">&#x27;name&#x27;</span>).<span class="hljs-title function_">required</span>(<span class="hljs-literal">true</span>);
}, <span class="hljs-regexp">/Cannot.*&#x27;required&#x27;/</span>);

<span class="hljs-comment">// To make a nested object required, use a single nested schema</span>
Expand Down
Loading

0 comments on commit 674f782

Please sign in to comment.