Skip to content

Instantly share code, notes, and snippets.

View codedeep79's full-sized avatar

Nguyễn Trung Hậu codedeep79

View GitHub Profile
@codedeep79
codedeep79 / Xây dựng mạng xã hội Facebook (phần 1).md
Last active August 3, 2022 07:58
Xây dựng mạng xã hội Facebook (phần 1)

Build project directory structure

  • The assets folder stores metadata, css, and javascript resources
  • The connect directory stores database connection information
  • The core folder stores ajax information about the comment, share, like, and post system; database; user and post classes exchange data of client and server
  • The user directory stores user resources
@codedeep79
codedeep79 / List all collections in MongoDB database.md
Created August 3, 2022 08:29
List all collections in MongoDB database

Prerequisites: Installed MongoDB on Ubuntu

MongoDB is a NoSQL database, that stores documents in JSON format. A collection is an entity in MongoDB (ie similar to a table in RDBMS databases) that stores JSON documents.

You can use one of the following commands from Mongo Shell to list all available collections in the MongoDB database:

show collections

Or

@codedeep79
codedeep79 / MongoDB insertOne.md
Created August 3, 2022 08:46
MongoDB insertOne

The insertOne() method allows you to insert a single document into a collection. The insertOne() method has the following syntax:

db.collection.insertOne(
   <document>,
   { writeConcern: <document>}
)

The insertOne() method accepts two arguments:

@codedeep79
codedeep79 / MongoDB insertMany.md
Last active August 3, 2022 09:22
MongoDB insertMany

The insertMany() allows you to insert multiple documents into a collection. Here is the syntax of the insertMany() method:

 db.collection.insertMany(
   [document1, document2, ...],
   {
      writeConcern: <document>,
      ordered: <boolean>
   }
)
@codedeep79
codedeep79 / Lấy dữ liệu trong MongoDB (phần 1).md
Last active August 3, 2022 12:48
Lấy dữ liệu trong MongoDB (phần 1)

The findOne() returns a single document from a collection that satisfies the specified condition.

The findOne() method has the following syntax:

db.collection.findOne(query, projection)

The findOne() accepts two optional arguments: query and projection.

  • The query is a document that specifies the selection criteria.
  • The projection is a document that specifies the fields in the matching document that you want to return.
@codedeep79
codedeep79 / Lấy dữ liệu trong MongoDB (phần 2).md
Created August 3, 2022 13:06
Lấy dữ liệu trong MongoDB (phần 2)

The find() method finds the documents that satisfy a specified condition and returns a cursor to the matching documents.

The following shows the syntax of the find() method:

db.collection.find(query, projection)

query: The query is a document that specifies the criteria for selecting documents from the collection. If you omit the query or pass an empty document({}), the find() returns a cursor that returns all documents in the collection.

projection: The projection is a document that specifies the fields in the matching documents to return. If you omit the projection argument, the find() method returns all fields in the matching documents.

@codedeep79
codedeep79 / Lấy dữ liệu trong MongoDB (phần 3).md
Created August 3, 2022 13:35
Lấy dữ liệu trong MongoDB (phần 3)

In this tutorial, you’ll how to use the MongoDB projection that allows you to select fields to return from a query. In MongoDB, projection simply means selecting fields to return from a query.

To determine if a field is included in the returned documents, you use the following syntax: { <field>: value, ...}

If the value is 1 or true, the is included in the matching documents. In case the value is 0 or false, it is suppressed from the returned documents.

If the projection document is empty {}, all the available fields will be included in the returned documents.

To specify a field in an embedded document, you use the following dot notation:

@codedeep79
codedeep79 / Xóa dữ liệu trong MongoDB (phần 1).md
Last active August 4, 2022 02:04
Xóa dữ liệu trong MongoDB (phần 1)

The deleteOne() method allows you to delete a single document from a collection.

The deleteOne() method has the following syntax:

db.collection.deleteOne(filter, option)

The deleteOne() method accepts two arguments:

  • filter is an required argument. The filter is a document that specifies the condition for matching the document to remove. If you pass an empty document {} into the method, it’ll delete the first document in the collection.
  • option is an optional argument. The option is a document that specifies the deletion options.
@codedeep79
codedeep79 / Xóa dữ liệu trong MongoDB (phần 2).md
Created August 4, 2022 02:24
Xóa dữ liệu trong MongoDB (phần 2)

The deleteMany() method allows you to remove all documents that match a condition from a collection.

The deleteMany() has the following syntax:

db.collection.deleteMany(filter, option)

In this syntax:

  • filter is a document that specifies deletion criteria. If the filter is an empty document {}, the deleteMany() method will delete all documents from the collection.
  • option is a document that specifies the deletion option.
@codedeep79
codedeep79 / Cập nhật dữ liệu trong MongoDB (phần 1).md
Created August 4, 2022 03:03
Cập nhật dữ liệu trong MongoDB (phần 1)

The updateOne() method allows you to update a single document that satisfies a condition.

The following shows the syntax of the updateOne() method:

db.collection.updateOne(filter, update, options)

In this syntax:

  • The filter is a document that specifies the criteria for the update. If the filter matches multiple documents, then the updateOne() method updates only the first document. If you pass an empty document {} into the method, it will update the first document returned in the collection.
  • The update is a document that specifies the change to apply.