The Journey of #100DaysOfCode (@Amir_BouGhanem)

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฌ - ๐—ฒ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜.๐—ถ๐—ป๐—ป๐—ฒ๐—ฟ๐—›๐—ง๐— ๐—Ÿ :closed_book:

Hello everyone! It is day 20 of the 100 days of code challenge. Weโ€™re 1/5 of the way there! For the next couple of days, I will be tackling some important JavaScript element content manipulation properties we can use to dynamically change the content of our HTML elements.
Today, I will be talking about .๐—ถ๐—ป๐—ป๐—ฒ๐—ฟ๐—›๐—ง๐— ๐—Ÿ. As the name implies, . ๐—ถ๐—ป๐—ป๐—ฒ๐—ฟ๐—›๐—ง๐— ๐—Ÿ allows us to alter the HTML inside of our element. Remember when we recently talked about template literals? Well, .innerHTML is vital in order for us to take advantage of interpolation and insert variable values into our element content. To help explain it better, I have provided an image that explains what .innerHTML can do and how it is used.

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿญ - ๐—ฒ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜.๐˜๐—ฒ๐˜…๐˜๐—–๐—ผ๐—ป๐˜๐—ฒ๐—ป๐˜ :closed_book:

.๐˜๐—ฒ๐˜…๐˜๐—–๐—ผ๐—ป๐˜๐—ฒ๐—ป๐˜ is a property in JavaScript that is used to get or set the text content of an element. There are a few things to note about this property:

  • It includes all text content in the element and its descendants, but not the HTML tags.
  • It is generally more secure to use .๐˜๐—ฒ๐˜…๐˜๐—–๐—ผ๐—ป๐˜๐—ฒ๐—ป๐˜ when inserting user-generated content, as to avoid the risk of executing malicious HTML scripts.

100daysofcode lebanon-mug

3 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฎ - ๐—ฒ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜.๐˜€๐—ฒ๐˜๐—”๐˜๐˜๐—ฟ๐—ถ๐—ฏ๐˜‚๐˜๐—ฒ() :closed_book:

The ๐˜€๐—ฒ๐˜๐—”๐˜๐˜๐—ฟ๐—ถ๐—ฏ๐˜‚๐˜๐—ฒ() method in JavaScript is used to add a new attribute or change the value of an existing attribute on an HTML element. It takes two arguments: the name of the attribute and the value you want to set for that attribute.

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฏ - ๐—–๐—น๐—ฎ๐˜€๐˜€ ๐—Ÿ๐—ถ๐˜€๐˜ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ :closed_book:
The โ€œ๐—ฐ๐—น๐—ฎ๐˜€๐˜€๐—Ÿ๐—ถ๐˜€๐˜โ€ property in JavaScript is a read-only property that returns a live collection of an elementโ€™s classes. It is useful for manipulating an elementโ€™s classes without having to work with string such as className.
Here are some of the methods we can use with โ€œ๐—ฐ๐—น๐—ฎ๐˜€๐˜€๐—Ÿ๐—ถ๐˜€๐˜โ€:

  1. add(): Adds one or more classes to the element.
  2. remove(): Removes one or more classes from the element.
  3. toggle(): Toggles the existing class. If is present, removes it, else, it adds it.
  4. contains(): Boolean. Returns โ€˜trueโ€™ if the element contains the specified class; otherwise, returns โ€˜falseโ€™.
  5. replace(oldClass, newClass): Replaces an existing class with a new one.

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฐ - ๐—˜๐˜ƒ๐—ฒ๐—ป๐˜ ๐—Ÿ๐—ถ๐˜€๐˜๐—ฒ๐—ป๐—ฒ๐—ฟ๐˜€ :closed_book:

๐—˜๐˜ƒ๐—ฒ๐—ป๐˜ ๐—Ÿ๐—ถ๐˜€๐˜๐—ฒ๐—ป๐—ฒ๐—ฟ๐˜€ in JavaScript are functions that wait for an event to occur on a particular element (like a button or a div) and then execute a specified function when the event happens!
They are necessary and vital when it comes to adding dynamic actions to your websites. To create an event listener on a button for example, simply select the button element in JavaScript to start. After that, all you have to do is button.addEventListener(). It takes 2 parameters, the event, and the function to be executed once the event occurs. Some common event types include but not limited to:

  • โ€˜clickโ€™: Fired when the element is clicked.
  • โ€˜mouseoverโ€™: Fired when the mouse pointer is moved onto an element (hover)
  • โ€˜mouseoutโ€™: Fired when the mouse pointer is moved off of an element.
  • โ€˜keydownโ€™: Fired when a key is pressed down. (Similar to โ€˜keypressโ€™)
  • โ€˜keyupโ€™: Fired when a key is released.
    Also, what makes event listeners extra useful is that we can pass a parameter (usually event) to the callback function that allows us to access the nature of the event so that we have more control.

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฑ - ๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ฎ ๐—•๐—ฎ๐—ฐ๐—ธ๐—ฒ๐—ป๐—ฑ? :closed_book:

It is day 25 of the 100daysofcode challenge! Iโ€™m more than excited to start sharing my acquired knowledge in Backend Development. Letโ€™s get started!

A ๐—•๐—ฎ๐—ฐ๐—ธ๐—ฒ๐—ป๐—ฑ refers to the server-side of a web application or system that handles the business logic, database interactions, authentication, and server configuration. There are 3 key components of a backend:

๐’๐ž๐ซ๐ฏ๐ž๐ซ

  • Web Server: Handles HTTP requests from clients (e.g., Apache).

  • Application Server: Executes application logic (e.g., Node.js, Django, Flask, Ruby on Rails).

  1. ๐ƒ๐š๐ญ๐š๐›๐š๐ฌ๐ž

Stores and retrieves data. Common types include Relational databases (e.g., MySQL, PostgreSQL) and NoSQL databases (e.g, MongoDB, Cassandra).

  1. ๐€๐ฉ๐ฉ๐ฅ๐ข๐œ๐š๐ญ๐ข๐จ๐ง
  • Programming Languages: Core logic written in languages like JavaScript, Python, Ruby, Java, PHP.

  • APIs: Interfaces for frontend-backend communication (e.g, RESTful APIs, GraphQL).

  • Authentication and Authorization: User identity verification and access control (e.g, OAuth).

100daysofcode lebanon-mug

image

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿฒ - ๐—ฆ๐—ค๐—Ÿ ๐˜ƒ๐˜€ ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ :closed_book:

Letโ€™s look at 3 key differences between ๐—ฆ๐—ค๐—Ÿ (relational databases) and ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ (non-relational databases):

  1. ๐ƒ๐š๐ญ๐š ๐Œ๐จ๐๐ž๐ฅ: ๐—ฆ๐—ค๐—Ÿ databases use structured schema with predefined tables and columns.
    ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ databases use unstructured or semi-structured data, meaning that they can handle various data formats, including documents, key-value pairs, graphs, and others (This offers more flexibility).
    ๐—ฆ๐—ค๐—Ÿ uses relational data models.
    ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ uses flexible schemas, meaning you can add fields as you go along.
  2. ๐’๐œ๐š๐ฅ๐š๐›๐ข๐ฅ๐ข๐ญ๐ฒ: ๐—ฆ๐—ค๐—Ÿ databases scale vertically by increasing hardware capacity of a single server (scale up) because it can be challenging to scale horizontally (add more servers).
    ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ databases are usually designed to scale horizontally (distribute data across multiple servers). For example, by utilizing MongoDB sharded clusters, we can easily achieve this flexible scaling.
  3. ๐๐ฎ๐ž๐ซ๐ฒ ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž: ๐—ฆ๐—ค๐—Ÿ databases use Structured Query Language (SQL) for defining and manipulating data.
    Different ๐—ก๐—ผ๐—ฆ๐—ค๐—Ÿ databases use different query languages, which can be specific to the database type (e.g., MongoDB uses a query language similar to JSON called MQL - MongoDB Query Language while Cassandra uses CQL).

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿณ - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—• :closed_book:

In my internship with TECHlarious & Two Of Us, Iโ€™ll be working with MongoDB as the database for my backend. ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—• is a leading NoSQL technology. For those of you who donโ€™t know, NoSQL โ†’ non-relational databases. NoSQL specializes in speed and structure flexibility (as there are no limitations). ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—• is an open source, schema-less, and document-based database with a horizontal scale-out architecture. It also offers multiple services like ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—• ๐—–๐—ผ๐—บ๐—ฝ๐—ฎ๐˜€๐˜€, a GUI for MongoDB, ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—• ๐—ฅ๐—ฒ๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—น ๐— ๐—ถ๐—ด๐—ฟ๐—ฎ๐˜๐—ผ๐—ฟ, a SQL to MongoDB database migrator that lets you transform your relational databases to non-relational in seconds. Last but not least, MongoDB offers ๐—”๐˜๐—น๐—ฎ๐˜€, a global cloud database that gives you the ability to deploy to cloud providers like Google Cloud, AWS, and Azure without worrying about vendor lock. I love MongoDB :heart_eyes:

100daysofcode lebanon-mug

image

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿ– - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ is an elegant MongoDB object modeling tool for MongoDB & Node.js. It provides a higher-level abstraction for working with MongoDB data, allowing developers to define schemas and interact with MongoDB databases in a more structured way.

100daysofcode lebanon-mug


2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿต - ๐—ก๐—ผ๐—ฑ๐—ฒ.๐—ท๐˜€ :closed_book:

๐—ก๐—ผ๐—ฑ๐—ฒ.๐—ท๐˜€ is a runtime environment that allows you to run JavaScript code outside of a web browser. It is built on the V8 JavaScript engine, which is the same engine that powers Google Chrome. Node.js enables JavaScript to be used for server-side programming, which means you can write server-side code using JavaScript.

  1. ๐„๐ฏ๐ž๐ง๐ญ-๐ƒ๐ซ๐ข๐ฏ๐ž๐ง ๐š๐ง๐ ๐๐จ๐ง-๐๐ฅ๐จ๐œ๐ค๐ข๐ง๐  ๐ˆ/๐Ž:

Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight and efficient. This allows Node.js to handle many connections simultaneously.

  1. ๐’๐ข๐ง๐ ๐ฅ๐ž-๐“๐ก๐ซ๐ž๐š๐๐ž๐:

Node.js operates on a single-threaded event loop, which handles all asynchronous operations. This is different from traditional server models that use multiple threads to handle requests.

  1. ๐๐š๐œ๐ค๐š๐ ๐ž ๐Œ๐š๐ง๐š๐ ๐ž๐ฆ๐ž๐ง๐ญ:

Node.js comes with npm (Node Package Manager), which is the largest ecosystem of open-source libraries in the world. This makes it easy to find and use packages to add functionality to your Node.js applications.

  1. ๐‰๐š๐ฏ๐š๐’๐œ๐ซ๐ข๐ฉ๐ญ ๐„๐ฏ๐ž๐ซ๐ฒ๐ฐ๐ก๐ž๐ซ๐ž:

With Node.js, you can use JavaScript for both front-end and back-end development, creating a more seamless and consistent development experience.

  1. ๐’๐œ๐š๐ฅ๐š๐›๐ข๐ฅ๐ข๐ญ๐ฒ:

Node.js is designed to be scalable. Its non-blocking I/O model is particularly well-suited for real-time applications that require a lot of I/O operations, such as chat applications, online games, and collaborative tools.

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฌ - ๐—บ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ.๐—ฐ๐—ผ๐—ป๐—ป๐—ฒ๐—ฐ๐˜() :closed_book:

The ๐—บ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ.๐—ฐ๐—ผ๐—ป๐—ป๐—ฒ๐—ฐ๐˜ function is used to establish a connection to a MongoDB database. It takes 2 parameters:

  • MongoDB database URL to establish a connection with.
  • options: Like useNewUrlParser & useUnifiedTopology.

100daysofcode lebanon-mug


2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿญ - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ ๐—ฆ๐—ฐ๐—ต๐—ฒ๐—บ๐—ฎ :closed_book:

Creating a Mongoose schema involves defining the structure and data types for documents in a MongoDB collection. This schema is used to model the data in your application, providing a blueprint for how each document should look. To create a mongoose schema, we use mongoose.Schema() which takes as an object detailing how the schema should be laid out. Below is an example on how we can utilize Mongoose to create a user schema for our MongoDB database:

100daysofcode lebanon-mug

2 Likes

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฎ - $๐—ผ๐—ฟ ๐—ถ๐—ป ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

In Mongoose, the $or operator is used to perform a logical OR query on multiple conditions. It matches documents that satisfy at least one of the specified conditions.
In the example below:
The query will return documents where the age is greater than 30 or the location is โ€œNew York.โ€
The $or operator takes an array of conditions, and the query matches documents that satisfy any of these conditions.
You can adjust the conditions and fields as needed for your specific use case.

100daysofcode lebanon-mug

1 Like

๐Ÿ“• ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฏ - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ ๐— ๐—ถ๐—ฑ๐—ฑ๐—น๐—ฒ๐˜„๐—ฎ๐—ฟ๐—ฒ ๐Ÿ“•

Mongoose middleware, also known as Mongoose hooks, allows you to perform actions before or after certain operations in your Mongoose models. Middleware is particularly useful for adding logic that should run automatically, such as data validation, logging, or modifying data before it is saved to the database.

๐“๐ฒ๐ฉ๐ž๐ฌ ๐จ๐Ÿ ๐Œ๐ข๐๐๐ฅ๐ž๐ฐ๐š๐ซ๐ž

Mongoose supports two types of middleware:

๐๐ซ๐ž ๐Œ๐ข๐๐๐ฅ๐ž๐ฐ๐š๐ซ๐ž:

Runs before a particular action.

Commonly used for tasks like validation, modification of data, or authentication.

๐๐จ๐ฌ๐ญ ๐Œ๐ข๐๐๐ฅ๐ž๐ฐ๐š๐ซ๐ž:

Runs after an action is completed.

Often used for tasks like logging, sending notifications, or cleanup tasks.

๐‚๐จ๐ฆ๐ฆ๐จ๐ง ๐Ž๐ฉ๐ž๐ซ๐š๐ญ๐ข๐จ๐ง๐ฌ ๐“๐ก๐š๐ญ ๐’๐ฎ๐ฉ๐ฉ๐จ๐ซ๐ญ ๐Œ๐ข๐๐๐ฅ๐ž๐ฐ๐š๐ซ๐ž:

๐ฌ๐š๐ฏ๐ž: Triggered when a document is saved to the database.

๐ซ๐ž๐ฆ๐จ๐ฏ๐ž: Triggered when a document is removed.

๐ฎ๐ฉ๐๐š๐ญ๐ž๐Ž๐ง๐ž: Triggered when a single document is updated.

๐Ÿ๐ข๐ง๐๐Ž๐ง๐ž๐€๐ง๐๐”๐ฉ๐๐š๐ญ๐ž: Triggered when a single document is found and updated.

๐Ÿ๐ข๐ง๐: Triggered when documents are retrieved from the database.

100daysofcode lebanon-mug


1 Like

๐Ÿ“• ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฐ - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ ๐—ฉ๐—ฎ๐—น๐—ถ๐—ฑ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐Ÿ“•

Mongoose validation is a crucial feature that helps enforce data integrity and consistency in your MongoDB documents by ensuring that the data adheres to specific rules before being saved to the database. Mongoose provides built-in validators, custom validators, and even asynchronous validation to handle complex validation scenarios.

๐“๐ฒ๐ฉ๐ž๐ฌ ๐จ๐Ÿ ๐Œ๐จ๐ง๐ ๐จ๐จ๐ฌ๐ž ๐•๐š๐ฅ๐ข๐๐š๐ญ๐ข๐จ๐ง

  1. ๐๐ฎ๐ข๐ฅ๐ญ-๐ข๐ง ๐•๐š๐ฅ๐ข๐๐š๐ญ๐จ๐ซ๐ฌ:
  • Mongoose offers several built-in validators that you can apply directly in your schema definitions. Some common ones include:
    • required : Ensures a field is not empty.
    • min and max : Validate numerical ranges.
    • enum : Ensures the value is one of the specified options.
    • match : Validates that a string matches a given regular expression.
    • minlength and maxlength : Validate the length of a string.

In the example below:

  • The username field is required and must be at least 3 characters long.
  • The age field must be between 18 and 65.
  • The email field must match the pattern for a typical email address.
  • The role field can only be either โ€˜userโ€™ or โ€˜adminโ€™.

๐‚๐ฎ๐ฌ๐ญ๐จ๐ฆ ๐•๐š๐ฅ๐ข๐๐š๐ญ๐จ๐ซ๐ฌ:

  • You can define your own validation logic if the built-in validators donโ€™t meet your needs.

In the example below:

  • The username field has a custom validator that only allows alphanumeric characters.
  • If the validation fails, an error message is generated using the provided message function.

๐€๐ฌ๐ฒ๐ง๐œ๐ก๐ซ๐จ๐ง๐จ๐ฎ๐ฌ ๐•๐š๐ฅ๐ข๐๐š๐ญ๐ข๐จ๐ง:

  • Sometimes, validation requires asynchronous operations, such as checking the uniqueness of a field against the database.

In the example below:

  • The email field is validated to ensure it is unique in the database.
  • The custom validator is asynchronous, and it uses the callback function to indicate whether the validation passed or failed.

100daysofcode lebanon-mug

code1
code2
code3

1 Like

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฑ - ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ ๐—”๐—ด๐—ด๐—ฟ๐—ฒ๐—ด๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ๐˜€ :closed_book:

Aggregation pipelines in Mongoose are a powerful feature that allows you to perform complex data processing and transformation operations on your MongoDB documents. The aggregation framework processes data through a series of stages, where each stage performs a specific operation and passes the result to the next stage.

๐Š๐ž๐ฒ ๐‚๐จ๐ง๐œ๐ž๐ฉ๐ญ๐ฌ

  • ๐’๐ญ๐š๐ ๐ž๐ฌ : Each stage in an aggregation pipeline performs an operation on the data. Common stages include:
    • $match : Filters documents based on a specified condition, similar to a find query.
    • $group : Groups documents by a specified key and can perform aggregate calculations like sum, average, count, etc.
    • $sort : Sorts documents based on a specified field.
    • $project : Reshapes documents by including, excluding, or computing new fields.
    • $lookup : Performs a left outer join with another collection to merge data.
    • $unwind : Deconstructs an array field into multiple documents.

๐”๐ฌ๐ž ๐‚๐š๐ฌ๐ž๐ฌ

Aggregation pipelines are ideal for:

  • ๐ƒ๐š๐ญ๐š ๐€๐ง๐š๐ฅ๐ฒ๐ฌ๐ข๐ฌ: Performing complex calculations, such as totals, averages, and other statistics.
  • ๐ƒ๐š๐ญ๐š ๐“๐ซ๐š๐ง๐ฌ๐Ÿ๐จ๐ซ๐ฆ๐š๐ญ๐ข๐จ๐ง : Reshaping documents, extracting specific fields, or flattening nested structures.
  • ๐ƒ๐š๐ญ๐š ๐Œ๐ž๐ซ๐ ๐ข๐ง๐ : Combining data from different collections or fields using stages.

100daysofcode lebanon-mug

1 Like

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿฒ - .๐—ณ๐—ถ๐—ป๐—ฑ() ๐—ถ๐—ป ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

The .find() method in Mongoose is used to query documents from a MongoDB collection that match certain criteria. It returns an array of documents that satisfy the query conditions. Below is an overview of how .find() works and how you can use it effectively:

100daysofcode lebanon-mug

1 Like

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿณ - .๐—บ๐—ผ๐—ฑ๐—ฒ๐—น() ๐—ถ๐—ป ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

The .model() method in Mongoose is a fundamental part of how you interact with MongoDB collections in your application. This method is used to create a Mongoose model, which is a wrapper for a MongoDB collection. Models are responsible for creating and reading documents from the underlying MongoDB database.

When you define a schema in Mongoose, it describes the structure of documents in a collection. The .model() method compiles this schema into a model that you can use to interact with that collection.
The .model() method is essential for defining how your application interacts with the data in MongoDB. It acts as the bridge between your code and the database, providing a structured way to manage, validate, and query your data.

100daysofcode lebanon-mug

1 Like

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿด - .๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜๐—ฒ() ๐—ถ๐—ป ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

The .create() method in Mongoose is a convenient way to create and save a new document (or multiple documents) to a MongoDB collection in one step. This method is a shortcut for creating an instance of a model and then calling .save() on it.

100daysofcode lebanon-mug

1 Like

:closed_book: ๐——๐—ฎ๐˜† ๐Ÿฏ๐Ÿต - .๐—ฐ๐—ผ๐˜‚๐—ป๐˜๐——๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜๐˜€() ๐—ถ๐—ป ๐— ๐—ผ๐—ป๐—ด๐—ผ๐—ผ๐˜€๐—ฒ :closed_book:

The .countDocuments() method in Mongoose is used to count the number of documents in a collection that match a given query. It provides a quick way to determine how many documents meet certain criteria without having to retrieve the documents themselves.

100daysofcode lebanon-mug

1 Like