<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Seyyed Ali Mohseni on Medium]]></title>
        <description><![CDATA[Stories by Seyyed Ali Mohseni on Medium]]></description>
        <link>https://medium.com/@mohseni676?source=rss-af9b3a216ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g_EWuczuxWS3T3e2OYhhmg.jpeg</url>
            <title>Stories by Seyyed Ali Mohseni on Medium</title>
            <link>https://medium.com/@mohseni676?source=rss-af9b3a216ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 23:27:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohseni676/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Nest.js Mongoose ODM zero to hero (part 3) — formatting outputs in Nest.js/Mongoose]]></title>
            <link>https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-3-formatting-outputs-in-nest-js-mongoose-3bb5444f1506?source=rss-af9b3a216ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bb5444f1506</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[mongoose]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Seyyed Ali Mohseni]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 09:22:14 GMT</pubDate>
            <atom:updated>2023-06-25T10:14:14.548Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e?source=your_stories_page-------------------------------------">Nest.js Mongoose ODM zero to hero (part 3)</a> — formatting outputs in Nest.js/Mongoose</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HAltHPKPSSa6b4uWdOBA_w.jpeg" /><figcaption><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e?source=your_stories_page-------------------------------------">Nest.js Mongoose ODM zero to hero (part 3)</a> — formatting outputs in Nest.js/Mongoose</figcaption></figure><p>In part2 (the previous part), described how to make relations between Mongoose schemas in the Nest.js framework using “<a href="https://www.npmjs.com/package/@nestjs/mongoose">@nestjs/mongoose</a>” package.</p><ul><li><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e">Nest.js Mongoose ODM zero to hero (part 1)</a></li><li><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-2-3058d5361ae1">Nest.js Mongoose ODM zero to hero (part 2)</a></li></ul><p>Today I want to describe the ways of changing output data from a Mongoose schema in Nest.js schema class.</p><blockquote>Before of everything, all the “Previous records” that were created based on the old schema (created in part 1) must be deleted. Because may we have encountered errors related to the Irritation “obj_items” in this part of the tutorial.</blockquote><p>Ok, let’s do it…</p><p><strong>The power of “@Schema” decorator</strong></p><p>The “@Schema” decorator in Nest.js schema class introduces developers to lots of options for changing output.</p><p>Two common options in this decorator are</p><ul><li>toObject: the way of changing the output object on query current schema defined in this option.</li><li>toJson: we can customize JSON output with this feature.</li></ul><p><strong>Delete __v:</strong></p><p>If you look at the response of the request in Postman, will see a “__v” in every schema object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iIqPwO-Pw0WU__yTvjG8Wg.png" /><figcaption>__v in JSON output</figcaption></figure><p>What’s this “__v” field?</p><p>According to <a href="https://kb.objectrocket.com/mongo-db/understanding-the-mongoose-__v-field-1011">this article</a>:</p><blockquote>The __v field is called the version key. It describes the internal revision of a document. This __v field is used to track the revisions of a document. By default, its value is zero. In real practice, the __v field increments by one only when an array is updated. In other situations, the value of the __v field remains unaffected. So to keep the track of __v field in such situations, we can do it manually using the increment operator provided by the mongoose.</blockquote><p>We can delete that for JSON or Object very simply with disable that in the “toObject” and “toJson” options in the “@Schema” decorator of Nest.js. for example, I changed the “InvoiceSchema” as follows:</p><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Customer } from &quot;./customer.schema&quot;;<br>import { InvoiceItem } from &quot;./invoice-item.schema&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema({<br>    toObject:{<br>        //delete __v from output object<br>        versionKey: false<br>    },<br>    toJSON:{<br>        //delete __v from output JSON<br>        versionKey: false<br>    }<br>})<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    /*<br>    @Prop() <br>    customer_name: string<br>    @Prop()<br>    customer_phone: string <br>    */<br>    // 👆 this transform to this 👇 (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Customer&#39;})<br>    obj_customer: Customer<br><br>    /*<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>    */<br>    // 👆 this transform to this 👇 (OneToMany relation)<br>    @Prop({type:[<br>        {type: mongoose.Types.ObjectId, ref: &#39;InvoiceItem&#39;}<br>    ]})<br>    obj_items: [InvoiceItem]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);</pre><p>and the “__v” disappears from the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkG1F5Kx3bibpjezexhN7g.jpeg" /><figcaption>__v disappeared from the JSON output</figcaption></figure><p>But still, there are __v in related objects (“obj_items”, “obj_customer”).</p><p>They are also will disappear by doing the same with their schemas.</p><p><strong>Output “Time ” &amp; “Date ” separately derived from “invoice_date” field:</strong></p><p>In this challenge, I want to extract time (hh:mm:ss) and date (YYYY-MM-DD) as separate fields in the output JSON or object.</p><p>for this reason, the “transform” option will help, how?</p><blockquote>the “transform” option is a function that received the output of schema as the input parameter and change that then returns changed as JSON or object.</blockquote><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Customer } from &quot;./customer.schema&quot;;<br>import { InvoiceItem } from &quot;./invoice-item.schema&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema({<br>    toObject:{<br>        //delete __v from output object<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br>            // return edited object<br>            return ret;<br>        }<br>    },<br>    toJSON:{<br>        //delete __v from output JSON<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br>            // return edited object<br>            return ret;<br>        }<br>    }<br>})<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    /*<br>    @Prop() <br>    customer_name: string<br>    @Prop()<br>    customer_phone: string <br>    */<br>    // 👆 this transform to this 👇 (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Customer&#39;})<br>    obj_customer: Customer<br><br>    /*<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>    */<br>    // 👆 this transform to this 👇 (OneToMany relation)<br>    @Prop({type:[<br>        {type: mongoose.Types.ObjectId, ref: &#39;InvoiceItem&#39;}<br>    ]})<br>    obj_items: [InvoiceItem]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);</pre><p>Ok, it’s done.</p><blockquote>Maybe the logic of converting time and date is not correct, but our goal in this article is to learn the functionalities of Mongoose, so if there is the mistakes, I apologize to you…</blockquote><p>The output look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9EMsZpfQCFQBGIU02fL2g.jpeg" /><figcaption>added “date_of_invoice” and “time_of_invoice” in the JSON output</figcaption></figure><p><strong>How to delete a field from the output?</strong></p><p>It’s very simple by using the<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete"> “delete” operator</a>.</p><blockquote>The delete operator removes a property from an object. If the property&#39;s value is an object and there are no more references to the object, the object held by that property is eventually released automatically.</blockquote><p>I delete the “invoice_date” field from the output as the code below:</p><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Customer } from &quot;./customer.schema&quot;;<br>import { InvoiceItem } from &quot;./invoice-item.schema&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema({<br>    toObject:{<br>        //delete __v from output object<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br><br>            //delete invoice_date from output<br>            delete ret.invoice_date;<br>            <br>            // return edited object<br>            return ret;<br>        }<br>    },<br>    toJSON:{<br>        //delete __v from output JSON<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br><br>            //delete invoice_date from output<br>            delete ret.invoice_date;<br>            <br>            // return edited object<br>            return ret;<br>        }<br>    }<br>})<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    /*<br>    @Prop() <br>    customer_name: string<br>    @Prop()<br>    customer_phone: string <br>    */<br>    // 👆 this transform to this 👇 (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Customer&#39;})<br>    obj_customer: Customer<br><br>    /*<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>    */<br>    // 👆 this transform to this 👇 (OneToMany relation)<br>    @Prop({type:[<br>        {type: mongoose.Types.ObjectId, ref: &#39;InvoiceItem&#39;}<br>    ]})<br>    obj_items: [InvoiceItem]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);</pre><p>and the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsEgENAxa4RwlM-EE8KByQ.jpeg" /><figcaption>delete the “invoice_date” from the output</figcaption></figure><p><strong>I want to calculate the total sum of an invoice using the magic of virtual props…</strong></p><p>In the previous section, I described how to delete a field and transform output data using the “transform” option in the “@Schema” decorator of a Mongoose schema in Nest.js.</p><p>Here I will teach you how to use “virtual props” in your Mongoose schema.</p><p>As described in Mongoose documentation that In Mongoose: “a virtual is a property that is <strong>not</strong> stored in MongoDB. Virtuals are typically used for computed properties on documents.”</p><p>But how I can define a virtual in Nest.js Mongoose schema?</p><p>for this reason, we use the abilities of SchemaFactory.</p><p>I decide to calculate the sum of the invoice by multiplying each “good_price” field value in “good_amount” field value there is in the “obj_items” list and finally sum them as the “total” field in output.</p><p>So I add this part of the code at the bottom of the Invoice schema class file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJr2FndYXBIkHWo-6u_ajg.png" /><figcaption>define the total virtual prop for InvoiceSchema</figcaption></figure><p>And then add that to the output by listing that in the “virtuals” option of “@Schema” decorator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YlSiiAk7bEDOBQ6nqUtBpQ.png" /><figcaption>virtuals in “@Schema” decorator</figcaption></figure><p>the final schema will be similar to this:</p><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Customer } from &quot;./customer.schema&quot;;<br>import { InvoiceItem } from &quot;./invoice-item.schema&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema({<br>    toObject:{<br>        //delete __v from output object<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br><br>            //delete invoice_date from output<br>            delete ret.invoice_date;<br>            <br>            // return edited object<br>            return ret;<br>        },<br>        <br>        // virtual props<br>        virtuals: [&#39;total&#39;]<br>    },<br>    toJSON:{<br>        //delete __v from output JSON<br>        versionKey: false,<br>        //transform output<br>        transform: function(doc,ret,option){<br>            //get date from invoice_date<br>            const year =  ret.invoice_date.getFullYear();<br>            const month = ret.invoice_date.getMonth();<br>            const day = ret.invoice_date.getDate();<br>            ret.date_of_invoice = `${year}-${month+1}-${day}`<br>            //get time from invoice_date<br>            const h = ret.invoice_date.getHours();<br>            const m = ret.invoice_date.getMinutes();<br>            const s = ret.invoice_date.getSeconds();<br>            ret.time_of_invoice = `${h}:${m}:${s}`;<br><br>            //delete invoice_date from output<br>            delete ret.invoice_date;<br>            <br>            // return edited object<br>            return ret;<br>        },<br>        <br>        // virtual props<br>        virtuals: [&#39;total&#39;]<br>    }<br>})<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    /*<br>    @Prop() <br>    customer_name: string<br>    @Prop()<br>    customer_phone: string <br>    */<br>    // 👆 this transform to this 👇 (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Customer&#39;})<br>    obj_customer: Customer<br><br>    /*<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>    */<br>    // 👆 this transform to this 👇 (OneToMany relation)<br>    @Prop({type:[<br>        {type: mongoose.Types.ObjectId, ref: &#39;InvoiceItem&#39;}<br>    ]})<br>    obj_items: [InvoiceItem]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);<br><br>//create a virtual prop outputs total price of invoice<br>InvoiceSchema.virtual(&#39;total&#39;).get(function(){<br>    let total=0;<br>    <br>    for(let item of this.obj_items){<br>        <br>        total+= item.good_amount * item.good_price;<br>    }<br>    return total<br>})</pre><p>and the output JSON with the “total ” field at the end with the calculation of the sum:</p><pre>[<br>    {<br>        &quot;_id&quot;: &quot;6497e751f4a8228d9bf2c22d&quot;,<br>        &quot;obj_customer&quot;: {<br>            &quot;_id&quot;: &quot;6497e751f4a8228d9bf2c22b&quot;,<br>            &quot;name&quot;: &quot;Amir Mousavi&quot;,<br>            &quot;phone&quot;: &quot;0198726452&quot;,<br>            &quot;obj_invoices&quot;: [],<br>            &quot;__v&quot;: 0<br>        },<br>        &quot;obj_items&quot;: [<br>            {<br>                &quot;_id&quot;: &quot;6497e751f4a8228d9bf2c226&quot;,<br>                &quot;good_name&quot;: &quot;Pasta&quot;,<br>                &quot;good_amount&quot;: 2,<br>                &quot;good_price&quot;: 6,<br>                &quot;__v&quot;: 0<br>            },<br>            {<br>                &quot;_id&quot;: &quot;6497e751f4a8228d9bf2c227&quot;,<br>                &quot;good_name&quot;: &quot;White Rice&quot;,<br>                &quot;good_amount&quot;: 5,<br>                &quot;good_price&quot;: 8,<br>                &quot;__v&quot;: 0<br>            }<br>        ],<br>        &quot;total&quot;: 52,<br>        &quot;id&quot;: &quot;6497e751f4a8228d9bf2c22d&quot;,<br>        &quot;date_of_invoice&quot;: &quot;2023-4-3&quot;,<br>        &quot;time_of_invoice&quot;: &quot;3:0:0&quot;<br>    }<br>]</pre><p><strong>Conclusion:</strong></p><p>In this part of our journey, we learn how to format the outputs in Mongoose with the Nest.js framework.</p><p>Using these functionalities in the correct way is your responsibility. but I tried to describe everything as simply as possible.</p><p>In the next part, I will write about hooks in Mongoose. Please support me with your reshares these articles in everywhere you think is proper.</p><p>Git repo (step3):</p><p><a href="https://github.com/mohseni676/nestjs-mongoose-journey/tree/step3">https://github.com/mohseni676/nestjs-mongoose-journey/tree/step3</a></p><p>My LinkedIn profile:</p><p><a href="https://www.linkedin.com/in/seyyedalimohseni/">https://www.linkedin.com/in/seyyedalimohseni/</a></p><p>Thank you so much…❤️❤️❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bb5444f1506" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nest.js Mongoose ODM zero to hero (part 2)]]></title>
            <link>https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-2-3058d5361ae1?source=rss-af9b3a216ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/3058d5361ae1</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[schema]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[mongoose]]></category>
            <dc:creator><![CDATA[Seyyed Ali Mohseni]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 04:52:26 GMT</pubDate>
            <atom:updated>2023-06-25T09:28:16.492Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e">previous step (part 1)</a> we made a simple <a href="https://www.npmjs.com/package/@nestjs/mongoose">Mongoose </a>schema in the Nest.js framework.</p><p><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e">Nest.js Mongoose ODM zero to hero (part 1)</a></p><p>In this part of the tutorial, we work more on relations in Mongoose and the way of definition of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HAltHPKPSSa6b4uWdOBA_w.jpeg" /><figcaption>Complete guide to using <a href="https://mongoosejs.com/">Mongoose </a>in the <a href="https://nestjs.com/">Nest.js framework</a></figcaption></figure><p><strong>Split that…</strong></p><p>Before we defined the “InvoiceSchema” without any relationship but we can split that into three related schemas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqWQiawsH_lpz0MgPqGAbA.jpeg" /><figcaption>new class diagram</figcaption></figure><p>The schema design for “CustomerSchema” must be like the following code, so create a typescript schema class named “customer.schema.ts” in the schema folder of the accounting module:</p><pre>//src/accounting/schema/customer.schema.ts<br>import { Prop, Schema, SchemaFactory } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Invoice } from &quot;./invoice.schema&quot;;<br><br>export type CustomerDocument = HydratedDocument&lt;Customer&gt;<br><br>@Schema()<br>export class Customer{<br>    @Prop()<br>    name: string<br>    @Prop({unique: true})<br>    phone: string<br>    //Add one-to-many relation to InvoiceSchema<br>    @Prop({type:[<br>        {type : mongoose.Types.ObjectId , ref: &#39;Invoice&#39;}<br>    ]})<br>    obj_invoices: [Invoice]<br>}<br><br>export const CustomerSchema = SchemaFactory.createForClass(Customer);</pre><p>and for invoice items write a new schema with the name “InvoiceItemSchema”.</p><pre>//src/accounting/schema/invoice-item.schema.ts<br>import { Prop, Schema, SchemaFactory } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Invoice } from &quot;./invoice.schema&quot;;<br><br>export type InvoiceItemDocument = HydratedDocument&lt;InvoiceItem&gt;<br><br>@Schema()<br>export class InvoiceItem{<br>    @Prop()<br>    good_name: string<br>    @Prop()<br>    good_amount: number<br>    @Prop()<br>    good_price: number<br>    //Every InvoiceItem belongs to an Invoice (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Invoice&#39;})<br>    obj_invoice: Invoice<br>}<br><br>export const InvoiceItemSchema = SchemaFactory.createForClass(InvoiceItem)</pre><p>finally, change the “InvoiceSchema” to this:</p><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import mongoose, { HydratedDocument } from &quot;mongoose&quot;;<br>import { Customer } from &quot;./customer.schema&quot;;<br>import { InvoiceItem } from &quot;./invoice-item.schema&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema()<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    /*<br>    @Prop() <br>    customer_name: string<br>    @Prop()<br>    customer_phone: string <br>    */<br>    // 👆 this transform to this 👇 (ManyToOne relation)<br>    @Prop({type: mongoose.Types.ObjectId, ref: &#39;Customer&#39;})<br>    obj_customer: Customer<br><br>    /*<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>    */<br>    // 👆 this transform to this 👇 (OneToMany relation)<br>    @Prop({type:[<br>        {type: mongoose.Types.ObjectId, ref: &#39;InvoiceItem&#39;}<br>    ]})<br>    obj_items: [InvoiceItem]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);</pre><p>You can see I describe change with comments in the code.</p><p><strong>Modify services</strong></p><p>We must add these two new schemas to “MongooseModule”, so modify that in Accounting Module:</p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { AccountingController } from &#39;./accounting.controller&#39;;<br>import { MongooseModule } from &#39;@nestjs/mongoose&#39;;<br>import { Invoice, InvoiceSchema } from &#39;./schema/invoice.schema&#39;;<br>import { AccountingService } from &#39;./accounting.service&#39;;<br>import { Customer, CustomerSchema } from &#39;./schema/customer.schema&#39;;<br>import { InvoiceItem, InvoiceItemSchema } from &#39;./schema/invoice-item.schema&#39;;<br><br>@Module({<br>  imports: [<br>    MongooseModule.forFeature([<br>    {name: Invoice.name, schema: InvoiceSchema},<br>    // here<br>    {name: Customer.name, schema: CustomerSchema},<br>    {name: InvoiceItem.name, schema: InvoiceItemSchema}<br>  ])<br>],<br>  controllers: [AccountingController],<br>  providers: [AccountingService]<br>})<br>export class AccountingModule {}</pre><p>and now ready to inject these schemas in “accounting.service.ts” and write new methods for creating Customer and InvoiceItem.</p><p>The changes will be:</p><ul><li>Inject two new schemas in the service class.</li><li>Create a private method (“createOrFindCustomer“)for creating or finding customers based on his/her phone number (unique property).</li><li>Create a private method (“createInvoiceItems”) for creating the list of sub-items of an invoice.</li><li>modify “createInvoice” method adopting the new schemas.</li></ul><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { InjectModel } from &#39;@nestjs/mongoose&#39;;<br>import { Invoice } from &#39;./schema/invoice.schema&#39;;<br>import { Model } from &#39;mongoose&#39;;<br>import { CreateInvoiceDto } from &#39;./dto/create-invoice.dto&#39;;<br>import { Customer } from &#39;./schema/customer.schema&#39;;<br>import { InvoiceItem } from &#39;./schema/invoice-item.schema&#39;;<br><br>@Injectable()<br>export class AccountingService {<br>    constructor(<br>        @InjectModel(Invoice.name) private readonly invoiceModel:Model&lt;Invoice&gt;,<br>        @InjectModel(InvoiceItem.name) private readonly invoiceItemModel:Model&lt;InvoiceItem&gt;,<br>        @InjectModel(Customer.name) private readonly customerModel:Model&lt;Customer&gt;<br>    ){}<br><br>    async createInvoice(createIvoiceDto:CreateInvoiceDto):Promise&lt;Invoice&gt;{<br>        const {customer_name,customer_phone,invoice_date,obj_items} = createIvoiceDto;<br>        const invoiceItems = await this.createInvoiceItems(obj_items);<br>        const customer = await this.createOrFindCustomer({name: customer_name, phone: customer_phone});<br>        return await this.invoiceModel.create({invoice_date,obj_items: invoiceItems,obj_customer: customer});<br>    }<br><br>    async getAllInvoices():Promise&lt;Invoice[]&gt;{<br>        return await this.invoiceModel.find().populate(&#39;obj_customer&#39;).populate(&#39;obj_items&#39;).exec()<br>    }<br><br>    //create customer<br>    private async createOrFindCustomer(customerData:{name:string,phone:string}):Promise&lt;Customer&gt;{<br>        const customer=await this.customerModel.findOne({phone: customerData.phone}).exec();<br>        if(customer){<br>            return customer;<br>        }<br>        return await this.customerModel.create(customerData);<br>    }<br><br>    //create invoice item<br>    private async createInvoiceItems(invoiceItemData:[{good_name:string,good_amount:number,good_price:number}]):Promise&lt;InvoiceItem[]&gt;{<br>        return await this.invoiceItemModel.create(invoiceItemData);<br>    }<br>}</pre><p>All the modifications are done now, let’s run and test the project:</p><pre>npm run start:dev</pre><p>and call the create invoice endpoint in Postman again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ptzvx6bYsIR01qr3DkVm_w.png" /><figcaption>Request create invoice endpoint</figcaption></figure><p>and results will be:</p><pre>{<br>    &quot;invoice_date&quot;: &quot;2023-04-03T00:00:00.000Z&quot;,<br>    &quot;obj_customer&quot;: {<br>        &quot;name&quot;: &quot;Amir Mousavi&quot;,<br>        &quot;phone&quot;: 198726452,<br>        &quot;obj_invoices&quot;: [],<br>        &quot;_id&quot;: &quot;6497bfb4d39216a320b0bf7c&quot;,<br>        &quot;__v&quot;: 0<br>    },<br>    &quot;obj_items&quot;: [<br>        {<br>            &quot;good_name&quot;: &quot;Pasta&quot;,<br>            &quot;good_amount&quot;: 2,<br>            &quot;good_price&quot;: 6,<br>            &quot;_id&quot;: &quot;6497bfb4d39216a320b0bf77&quot;,<br>            &quot;__v&quot;: 0<br>        },<br>        {<br>            &quot;good_name&quot;: &quot;White Rice&quot;,<br>            &quot;good_amount&quot;: 5,<br>            &quot;good_price&quot;: 8,<br>            &quot;_id&quot;: &quot;6497bfb4d39216a320b0bf78&quot;,<br>            &quot;__v&quot;: 0<br>        }<br>    ],<br>    &quot;_id&quot;: &quot;6497bfb4d39216a320b0bf7e&quot;,<br>    &quot;__v&quot;: 0<br>}</pre><p>As you can see, the new invoice was created with a new structure and these are the changes:</p><ul><li>“obj_customer” has changed to an object with an id.</li><li>All items in “obj_items” are objects.</li></ul><p>let’s check the database structure, so open mongo-express:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnSHTXbEZCstQa08pwojTA.png" /><figcaption>database structure</figcaption></figure><p>The collection list has been changed and the “customers” and “invoiceitems” collections are added. These images show changes in every collection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxjW8H6lrnESI6osbD0wcg.jpeg" /><figcaption>the invoice document list, you can see the differences.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISzB06or8M1runsc8DbYyw.png" /><figcaption>The new document was created based on the relations</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ZlNqG8ul3JfyybTzIZhmg.png" /><figcaption>The customer collection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apNaTa5NtmnDv7MoYkpLpg.png" /><figcaption>The invoiceitems collection</figcaption></figure><p>The code repository (branch step2):</p><p><a href="https://github.com/mohseni676/nestjs-mongoose-journey/tree/step2">GitHub - mohseni676/nestjs-mongoose-journey at step2</a></p><p>My LinkedIn profile:</p><p><a href="https://www.linkedin.com/in/seyyedalimohseni/">https://www.linkedin.com/in/seyyedalimohseni/</a></p><p>In the next part, I will talk about the Mongoose schema output formatting in the Nest.js framework and virtual properties.</p><p>Part3:</p><p><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-3-formatting-outputs-in-nest-js-mongoose-3bb5444f1506">Nest.js Mongoose ODM zero to hero (part 3) — formatting outputs in Nest.js/Mongoose</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3058d5361ae1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nest.js Mongoose ODM zero to hero (part 1)]]></title>
            <link>https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-1-8660952931e?source=rss-af9b3a216ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/8660952931e</guid>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[nestjs-tutorial]]></category>
            <category><![CDATA[mongoose]]></category>
            <dc:creator><![CDATA[Seyyed Ali Mohseni]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 12:45:10 GMT</pubDate>
            <atom:updated>2023-06-25T04:53:09.758Z</atom:updated>
            <content:encoded><![CDATA[<p>After doing many projects using the brilliant <a href="https://nestjs.com/">Nest.js framework</a> and doing some projects with <a href="https://mongoosejs.com/">Mongoose ODM</a>, I decided to write this document that describes the usage of that ODM in a Nest.js project correctly and how to deploy multiple functionalities of the <a href="https://www.npmjs.com/package/@nestjs/mongoose">@nestjs/mongoose</a> npm package in Nest.js framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HAltHPKPSSa6b4uWdOBA_w.jpeg" /><figcaption>Nest.js Mongoose ODM zero to hero</figcaption></figure><p>My goal is to write a complete guide for:</p><ul><li>How to create a simple Mongoose schema in Nest.js</li><li>How to develop relations between MongoDB collections (One-To-Many, One-To-One, and Many-To-Many)</li><li>How to format output data from a Mongoose schema using “toObject ” and “toJson” in Nest.js</li><li>How to handle events on a Mongoose schema in Nest.js like when a document is saved or deleted and …</li><li>How to use Mongoose middleware in Nest.js</li></ul><p><strong>Project Overview</strong></p><p>I want to create a simple invoice project and describe relations between schemas and use middleware in the right manner and define virtual props and …</p><p>let&#39;s begin</p><p><strong>Prerequisites</strong></p><p>during this journey, we need these tools:</p><ul><li>Node.js (version 18.06)</li><li>Docker (Desktop or server)</li></ul><h3>Step1 &gt; Warm-up</h3><p><strong>Generating project</strong></p><p>first of all, install Nest.js CLI using this command:</p><pre>npm install -g @nestjs/cli</pre><p>then generate a new project:</p><pre>nest new nest-mongoose-journey</pre><p>open the project using vs code with the following command:</p><pre>code nest-mongoose-journey</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F3kBzIr7jcih0nazHJtPcQ.png" /></figure><p>now must install the npm packages. open the terminal at the root of the project and run this command:</p><pre>npm install --save @nestjs/mongoose mongoose</pre><p>the project ready to start our journey.</p><p><strong>Run MongoDB server with Docker</strong></p><p>According to the <a href="https://hub.docker.com/_/mongo">MongoDB docker installation manual</a> in the docker hub, we start a new MongoDB server using the following compose config:</p><pre># Use root/example as user/password credentials<br>version: &#39;3.1&#39;<br><br>services:<br><br>  mongo:<br>    image: mongo<br>    container_name: mongo<br>    restart: always<br>    ports:<br>      - 27017:27017<br>    environment:<br>      MONGO_INITDB_ROOT_USERNAME: root<br>      MONGO_INITDB_ROOT_PASSWORD: example<br><br>  mongo-express:<br>    image: mongo-express<br>    container_name: mongo-express<br>    restart: always<br>    ports:<br>      - 8081:8081<br>    environment:<br>      ME_CONFIG_MONGODB_ADMINUSERNAME: root<br>      ME_CONFIG_MONGODB_ADMINPASSWORD: example<br>      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/</pre><p>To start the docker containers create a file in the root of the project with the name <em>mongo-compose.yml</em> and paste the above code on that and run the following command:</p><pre>docker compose -f mongo-compose.yml up -d</pre><p>let&#39;s check the docker running containers:</p><pre>docker ps</pre><p>and you must see two running containers with the names “<em>mongo ”</em>and “<em>mongo-express”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*veX38eDk5GdFyHCIyqQUrQ.png" /></figure><p>open a browser and browse the mongo-express URL: <a href="http://localhost:8081/">http://localhost:8081</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRIPHJjIQaYDSmqwmYwXEA.png" /><figcaption>mongo-express</figcaption></figure><p>As you can see, the MongoDB server is running successfully.</p><p>Now we are ready to config our project to connect the database.</p><p><strong>Mongoose connection</strong></p><p>We can make a connection to MongoDB in the Nest.js application using various manners:</p><ul><li>simple connection using URI.</li><li>useClass</li><li>useFactory</li></ul><p>In this step, we use the simple manner. for this create a module in the Nest.js app:</p><pre>nest generate module database</pre><p>and create a Mongoose connection by adding the following import to “/src/database/database.module.ts”:</p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { MongooseModule } from &#39;@nestjs/mongoose&#39;;<br><br>@Module({<br>    imports: [<br>        MongooseModule.forRoot(&quot;mongodb://root:example@127.0.0.1:27017/mongoose_journey?authSource=admin&quot;)<br>    ]<br>})<br>export class DatabaseModule {}</pre><p>This connection Uri makes a MongoDB database named “mongoose_journey”.</p><p>Let’s create our first schema named “InvoiceSchema”, so create a new module for “Accounting” with this:</p><pre>nest generate module accounting</pre><p>and also create a service and controller for the Accounting module:</p><pre>nest generate service accounting --no-spec<br>nest generate controller accounting --no-spec</pre><p><strong>Create the first schema</strong></p><p>Add a folder named “schema” in the accounting module directory and create a ts file for our invoice schema with the name “invoice.schema.ts”:</p><pre>import { Prop, Schema, SchemaFactory, raw } from &quot;@nestjs/mongoose&quot;;<br>import { HydratedDocument } from &quot;mongoose&quot;;<br><br>export type InvoiceDocument = HydratedDocument&lt;Invoice&gt;;<br><br>@Schema()<br>export class Invoice{<br>    @Prop({type: Date})<br>    invoice_date: Date<br>    @Prop()<br>    customer_name: string<br>    @Prop()<br>    customer_phone: string<br>    @Prop(raw([<br>        {<br>            good_name: String,<br>            good_price: Number,<br>            good_amount: Number<br>        }<br>    ]))<br>    obj_items: Record&lt;string,any&gt;[]<br>}<br><br>export const InvoiceSchema = SchemaFactory.createForClass(Invoice);</pre><p>The schema is designed for creating invoices and any invoice has items. the “obj_items” hold data for invoice items.</p><p>this is a simple invoice schema and in continuing we made it more structured.</p><p>for now, must register the schema in MongooseModule, so open “accounting.module.ts” and edit that like this:</p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { AccountingController } from &#39;./accounting.controller&#39;;<br>import { MongooseModule } from &#39;@nestjs/mongoose&#39;;<br>import { Invoice, InvoiceSchema } from &#39;./schema/invoice.schema&#39;;<br>import { AccountingService } from &#39;./accounting.service&#39;;<br><br>@Module({<br>  imports: [<br>    MongooseModule.forFeature([<br>    {name: Invoice.name, schema: InvoiceSchema}<br>  ])<br>],<br>  controllers: [AccountingController],<br>  providers: [AccountingService]<br>})<br>export class AccountingModule {}</pre><p><strong>Create services</strong></p><p>First of all, create DTO for the invoice creation method. Create the “dto” directory and then paste this code on “create-invoice.dto.ts” file inside that:</p><pre>export class CreateInvoiceDto{<br>    invoice_date: Date<br>    customer_name: string<br>    customer_phone: string<br>    obj_items: [<br>        {<br>            good_name: string,<br>            good_price: number,<br>            good_amount: number<br>        }<br>    ]<br>}</pre><p>Edit “accounting.service.ts” like this:</p><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { InjectModel } from &#39;@nestjs/mongoose&#39;;<br>import { Invoice } from &#39;./schema/invoice.schema&#39;;<br>import { Model } from &#39;mongoose&#39;;<br>import { CreateInvoiceDto } from &#39;./dto/create-invoice.dto&#39;;<br><br>@Injectable()<br>export class AccountingService {<br>    constructor(<br>        @InjectModel(Invoice.name) private readonly invoiceModel:Model&lt;Invoice&gt;<br>    ){}<br><br>    async createInvoice(createIvoiceDto:CreateInvoiceDto):Promise&lt;Invoice&gt;{<br>        return await this.invoiceModel.create(createIvoiceDto);<br>    }<br><br>    async getAllInvoices():Promise&lt;Invoice[]&gt;{<br>        return await this.invoiceModel.find().exec()<br>    }<br>}</pre><p><strong>Create controllers</strong></p><p>Open “accounting.controller.ts” and paste this code on it:</p><pre>import { Body, Controller, Get, Post } from &#39;@nestjs/common&#39;;<br>import { AccountingService } from &#39;./accounting.service&#39;;<br>import { CreateInvoiceDto } from &#39;./dto/create-invoice.dto&#39;;<br>import { Invoice } from &#39;./schema/invoice.schema&#39;;<br><br>@Controller(&#39;accounting&#39;)<br>export class AccountingController {<br>    constructor(<br>        private readonly accountingService:AccountingService<br>    ){}<br><br>    @Post(&#39;invoice&#39;)<br>    async createInvoice(@Body() createInvoiceDto:CreateInvoiceDto):Promise&lt;Invoice&gt;{<br>        return await this.accountingService.createInvoice(createInvoiceDto);<br>    }<br><br>    @Get(&quot;invoice/all&quot;)<br>    async getAllInvoices():Promise&lt;Invoice[]&gt;{<br>        return await this.accountingService.getAllInvoices()<br>    }<br>}</pre><p>All done in this step, let’s test it…</p><p>In the Postman app call the following URL with the “Post” method and JSON body content for example:</p><p>URL: <a href="http://http//localhost:3000/accounting/invoice">HTTP://localhost:3000/accounting/invoice</a></p><p>Method: Post</p><p>Body:</p><pre>{<br>    &quot;invoice_date&quot;: &quot;2023-04-03&quot;,<br>    &quot;customer_name&quot;: &quot;Seyyed Ali Mohseni&quot;,<br>    &quot;customer_phone&quot;: &quot;0123456789&quot;,<br>    &quot;obj_items&quot;: [<br>        {<br>            &quot;good_name&quot;: &quot;Blue cheese&quot;,<br>            &quot;good_price&quot;: 7.3,<br>            &quot;good_amount&quot;: 0.7<br>        },<br>        {<br>            &quot;good_name&quot;: &quot;Tomato paste&quot;,<br>            &quot;good_price&quot;: 12.9,<br>            &quot;good_amount&quot;: 1.4<br>        }<br>    ]<br>}</pre><p>The response must be like this:</p><pre>{<br>    &quot;invoice_date&quot;: &quot;2023-04-03T00:00:00.000Z&quot;,<br>    &quot;customer_name&quot;: &quot;Seyyed Ali Mohseni&quot;,<br>    &quot;customer_phone&quot;: &quot;0123456789&quot;,<br>    &quot;obj_items&quot;: [<br>        {<br>            &quot;good_name&quot;: &quot;Blue cheese&quot;,<br>            &quot;good_price&quot;: 7.3,<br>            &quot;good_amount&quot;: 0.7,<br>            &quot;_id&quot;: &quot;6496cc98899a9860b03124f8&quot;<br>        },<br>        {<br>            &quot;good_name&quot;: &quot;Tomato paste&quot;,<br>            &quot;good_price&quot;: 12.9,<br>            &quot;good_amount&quot;: 1.4,<br>            &quot;_id&quot;: &quot;6496cc98899a9860b03124f9&quot;<br>        }<br>    ],<br>    &quot;_id&quot;: &quot;6496cc98899a9860b03124f7&quot;,<br>    &quot;__v&quot;: 0<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s219aA5jvIeckY29cfTDEA.png" /><figcaption>create invoice request</figcaption></figure><p>If you call the “Get” method for the following URL, will respond list of invoices:</p><p>URL: <a href="http://localhost:3000/accounting/invoice/all">http://localhost:3000/accounting/invoice/all</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USyoyHe9zqkXN8x3_WY_6Q.png" /><figcaption>get all invoices request</figcaption></figure><p>You can check data in mongo-express:</p><p>Url: <a href="http://localhost:8081/">http://localhost:8081</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-7rVclBrlgj_SYDPQwrCg.png" /><figcaption>mongo express</figcaption></figure><p>you can find the git repo <a href="https://github.com/mohseni676/nestjs-mongoose-journey">here</a> [<a href="https://github.com/mohseni676/nestjs-mongoose-journey">https://github.com/mohseni676/nestjs-mongoose-journey</a>]</p><p><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-2-3058d5361ae1">In the next step</a>, I will describe how to deploy relations between Mongoose schemas.</p><p><a href="https://medium.com/@mohseni676/nest-js-mongoose-odm-zero-to-hero-part-2-3058d5361ae1">Nest.js Mongoose ODM zero to hero (part 2)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8660952931e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>