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 Dec 23, 2022
1 parent 31ee977 commit fe83049
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -7599,7 +7599,7 @@ <h4 id="example">
<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;&#118;&#101;&#110;&#117;&#x65;&#64;&#113;&#x2e;&#x63;&#111;&#109;">&#97;&#118;&#101;&#110;&#117;&#x65;&#64;&#113;&#x2e;&#x63;&#111;&#109;</a> can be registered for 2 accounts via <a href="mailto:&#97;&#x76;&#x65;&#110;&#x75;&#101;&#64;&#x71;&#x2e;&#x63;&#x6f;&#109;">&#97;&#x76;&#x65;&#110;&#x75;&#101;&#64;&#x71;&#x2e;&#x63;&#x6f;&#109;</a> and <a href="mailto:&#65;&#118;&#69;&#110;&#85;&#101;&#x40;&#x51;&#x2e;&#x43;&#x6f;&#x4d;">&#65;&#118;&#69;&#110;&#85;&#101;&#x40;&#x51;&#x2e;&#x43;&#x6f;&#x4d;</a>.</p>
having more than one account -- e.g., otherwise, <a href="mailto:&#x61;&#x76;&#101;&#110;&#x75;&#x65;&#64;&#x71;&#x2e;&#x63;&#111;&#109;">&#x61;&#x76;&#101;&#110;&#x75;&#x65;&#64;&#x71;&#x2e;&#x63;&#111;&#109;</a> can be registered for 2 accounts via <a href="mailto:&#97;&#x76;&#x65;&#x6e;&#x75;&#x65;&#x40;&#113;&#46;&#x63;&#x6f;&#x6d;">&#97;&#x76;&#x65;&#x6e;&#x75;&#x65;&#x40;&#113;&#46;&#x63;&#x6f;&#x6d;</a> and <a href="mailto:&#65;&#x76;&#x45;&#x6e;&#85;&#101;&#x40;&#x51;&#46;&#x43;&#111;&#77;">&#65;&#x76;&#x45;&#x6e;&#85;&#101;&#x40;&#x51;&#46;&#x43;&#111;&#77;</a>.</p>
<p>You can set up email lower case normalization easily via a Mongoose setter.</p>
<pre><code><span class="hljs-keyword">function</span> <span class="hljs-title function_">toLower</span>(<span class="hljs-params">v</span>) {
<span class="hljs-keyword">return</span> v.<span class="hljs-title function_">toLowerCase</span>();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/schematype.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ <h4 id="example">
<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;&#118;&#101;&#110;&#117;&#x65;&#64;&#113;&#x2e;&#x63;&#111;&#109;">&#97;&#118;&#101;&#110;&#117;&#x65;&#64;&#113;&#x2e;&#x63;&#111;&#109;</a> can be registered for 2 accounts via <a href="mailto:&#97;&#x76;&#x65;&#110;&#x75;&#101;&#64;&#x71;&#x2e;&#x63;&#x6f;&#109;">&#97;&#x76;&#x65;&#110;&#x75;&#101;&#64;&#x71;&#x2e;&#x63;&#x6f;&#109;</a> and <a href="mailto:&#65;&#118;&#69;&#110;&#85;&#101;&#x40;&#x51;&#x2e;&#x43;&#x6f;&#x4d;">&#65;&#118;&#69;&#110;&#85;&#101;&#x40;&#x51;&#x2e;&#x43;&#x6f;&#x4d;</a>.</p>
having more than one account -- e.g., otherwise, <a href="mailto:&#x61;&#x76;&#101;&#110;&#x75;&#x65;&#64;&#x71;&#x2e;&#x63;&#111;&#109;">&#x61;&#x76;&#101;&#110;&#x75;&#x65;&#64;&#x71;&#x2e;&#x63;&#111;&#109;</a> can be registered for 2 accounts via <a href="mailto:&#97;&#x76;&#x65;&#x6e;&#x75;&#x65;&#x40;&#113;&#46;&#x63;&#x6f;&#x6d;">&#97;&#x76;&#x65;&#x6e;&#x75;&#x65;&#x40;&#113;&#46;&#x63;&#x6f;&#x6d;</a> and <a href="mailto:&#65;&#x76;&#x45;&#x6e;&#85;&#101;&#x40;&#x51;&#46;&#x43;&#111;&#77;">&#65;&#x76;&#x45;&#x6e;&#85;&#101;&#x40;&#x51;&#46;&#x43;&#111;&#77;</a>.</p>
<p>You can set up email lower case normalization easily via a Mongoose setter.</p>
<pre><code><span class="hljs-keyword">function</span> <span class="hljs-title function_">toLower</span>(<span class="hljs-params">v</span>) {
<span class="hljs-keyword">return</span> v.<span class="hljs-title function_">toLowerCase</span>();
Expand Down
74 changes: 74 additions & 0 deletions docs/queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,80 @@ <h3 id="versus-aggregation"><a href="#versus-aggregation">Versus Aggregation</a>
<span class="hljs-comment">// pipelines.</span>
<span class="hljs-keyword">const</span> aggRes = <span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">aggregate</span>([{ <span class="hljs-attr">$match</span>: { <span class="hljs-attr">_id</span>: idString } }])
</code></pre>
<h3 id="sorting"><a href="#sorting">Sorting</a></h3>

<p><a href="/docs/api.html#query_Query-sort">Sorting</a> is how you can ensure you query results come back in the desired order.</p>
<pre><code class="language-javascript"><span class="hljs-keyword">const</span> personSchema = <span class="hljs-keyword">new</span> mongoose.<span class="hljs-title class_">Schema</span>({
<span class="hljs-attr">age</span>: <span class="hljs-title class_">Number</span>
});

<span class="hljs-keyword">const</span> <span class="hljs-title class_">Person</span> = mongoose.<span class="hljs-title function_">model</span>(<span class="hljs-string">&#x27;Person&#x27;</span>, personSchema);
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++) {
<span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">create</span>({ <span class="hljs-attr">age</span>: i });
}

<span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">find</span>().<span class="hljs-title function_">sort</span>({ <span class="hljs-attr">age</span>: -<span class="hljs-number">1</span> }); <span class="hljs-comment">// returns age starting from 10 as the first entry</span>
<span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">find</span>().<span class="hljs-title function_">sort</span>({ <span class="hljs-attr">age</span>: <span class="hljs-number">1</span> }); <span class="hljs-comment">// returns age starting from 0 as the first entry</span>
</code></pre>
<p>When sorting with mutiple fields, the order of the sort keys determines what key MongoDB server sorts by first.</p>
<pre><code class="language-javascript"><span class="hljs-keyword">const</span> personSchema = <span class="hljs-keyword">new</span> mongoose.<span class="hljs-title class_">Schema</span>({
<span class="hljs-attr">age</span>: <span class="hljs-title class_">Number</span>,
<span class="hljs-attr">name</span>: <span class="hljs-title class_">String</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-title class_">Number</span>
});

<span class="hljs-keyword">const</span> <span class="hljs-title class_">Person</span> = mongoose.<span class="hljs-title function_">model</span>(<span class="hljs-string">&#x27;Person&#x27;</span>, personSchema);
<span class="hljs-keyword">const</span> iterations = <span class="hljs-number">5</span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; iterations; i++) {
<span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">create</span>({
<span class="hljs-attr">age</span>: <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">abs</span>(<span class="hljs-number">2</span>-i),
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test&#x27;</span>+i,
<span class="hljs-attr">weight</span>: <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">floor</span>(<span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>() * <span class="hljs-number">100</span>) + <span class="hljs-number">1</span>
});
}

<span class="hljs-keyword">await</span> <span class="hljs-title class_">Person</span>.<span class="hljs-title function_">find</span>().<span class="hljs-title function_">sort</span>({ <span class="hljs-attr">age</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">weight</span>: -<span class="hljs-number">1</span> }); <span class="hljs-comment">// returns age starting from 0, but while keeping that order will then sort by weight.</span>
</code></pre>
<p>You can view the output of a single run of this block below.
As you can see, age is sorted from 0 to 2 but when age is equal, sorts by weight.</p>
<pre><code class="language-javascript">[
{
<span class="hljs-attr">_id</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">ObjectId</span>(<span class="hljs-string">&quot;63a335a6b9b6a7bfc186cb37&quot;</span>),
<span class="hljs-attr">age</span>: <span class="hljs-number">0</span>,
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test2&#x27;</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-number">67</span>,
<span class="hljs-attr">__v</span>: <span class="hljs-number">0</span>
},
{
<span class="hljs-attr">_id</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">ObjectId</span>(<span class="hljs-string">&quot;63a335a6b9b6a7bfc186cb35&quot;</span>),
<span class="hljs-attr">age</span>: <span class="hljs-number">1</span>,
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test1&#x27;</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-number">99</span>,
<span class="hljs-attr">__v</span>: <span class="hljs-number">0</span>
},
{
<span class="hljs-attr">_id</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">ObjectId</span>(<span class="hljs-string">&quot;63a335a6b9b6a7bfc186cb39&quot;</span>),
<span class="hljs-attr">age</span>: <span class="hljs-number">1</span>,
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test3&#x27;</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-number">73</span>,
<span class="hljs-attr">__v</span>: <span class="hljs-number">0</span>
},
{
<span class="hljs-attr">_id</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">ObjectId</span>(<span class="hljs-string">&quot;63a335a6b9b6a7bfc186cb33&quot;</span>),
<span class="hljs-attr">age</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test0&#x27;</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-number">65</span>,
<span class="hljs-attr">__v</span>: <span class="hljs-number">0</span>
},
{
<span class="hljs-attr">_id</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">ObjectId</span>(<span class="hljs-string">&quot;63a335a6b9b6a7bfc186cb3b&quot;</span>),
<span class="hljs-attr">age</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;Test4&#x27;</span>,
<span class="hljs-attr">weight</span>: <span class="hljs-number">62</span>,
<span class="hljs-attr">__v</span>: <span class="hljs-number">0</span>
}
]
</code></pre>
<h3 id="next"><a href="#next">Next Up</a></h3>

<p>Now that we&#39;ve covered <code>Queries</code>, let&#39;s take a look at <a href="validation.html">Validation</a>.</p>
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 @@ -49,7 +49,7 @@ <h2 id="getters">
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;&#46;&#x63;&#x6f;&#109;">&#97;&#98;&#x40;&#x67;&#109;&#x61;&#x69;&#x6c;&#46;&#x63;&#x6f;&#109;</a>&#39; in
MongoDB. If you save <code>user</code>, the <code>email</code> property will be &#39;<a href="mailto:&#97;&#98;&#x40;&#103;&#109;&#x61;&#x69;&#108;&#x2e;&#x63;&#x6f;&#109;">&#97;&#98;&#x40;&#103;&#109;&#x61;&#x69;&#108;&#x2e;&#x63;&#x6f;&#109;</a>&#39; in
the database.</p>
<p>By default, Mongoose executes 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>
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/virtuals.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2 id="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:&#x74;&#101;&#x73;&#x74;&#x40;&#x67;&#x6d;&#x61;&#105;&#108;&#46;&#x63;&#111;&#x6d;">&#x74;&#101;&#x73;&#x74;&#x40;&#x67;&#x6d;&#x61;&#105;&#108;&#46;&#x63;&#111;&#x6d;</a>&#39; is &#39;gmail.com&#39;.</p>
&#39;<a href="mailto:&#x74;&#x65;&#x73;&#x74;&#x40;&#103;&#109;&#x61;&#105;&#108;&#x2e;&#x63;&#111;&#109;">&#x74;&#x65;&#x73;&#x74;&#x40;&#103;&#109;&#x61;&#105;&#108;&#x2e;&#x63;&#111;&#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

0 comments on commit fe83049

Please sign in to comment.