https://github.com/suhailroushan13/mongodb-methods
MongoDB is a NoSQL document-oriented database system. It provides a rich set of methods and functions to interact with the database. Here are some of the most commonly used methods in MongoDB
https://github.com/suhailroushan13/mongodb-methods
config database db mongodb mongoose nosql-database
Last synced: 11 months ago
JSON representation
MongoDB is a NoSQL document-oriented database system. It provides a rich set of methods and functions to interact with the database. Here are some of the most commonly used methods in MongoDB
- Host: GitHub
- URL: https://github.com/suhailroushan13/mongodb-methods
- Owner: suhailroushan13
- Created: 2023-04-06T19:53:47.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T02:53:05.000Z (about 3 years ago)
- Last Synced: 2025-05-24T00:37:54.386Z (about 1 year ago)
- Topics: config, database, db, mongodb, mongoose, nosql-database
- Language: JavaScript
- Homepage: https://github.com/suhailroushan13/MongoDB-Methods
- Size: 17.6 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MongoDB-Methods
### MongoDB is a NoSQL document-oriented database system. It provides a rich set of methods and functions to interact with the database. Here are some of the most commonly used methods in MongoDB:
## Collection Management
- `db.collection()`: Returns a reference to a collection.
- `collection.countDocuments()`: Returns the number of documents in a collection.
- `collection.createIndex()`: Creates an index on a collection.
- `collection.deleteMany()`: Deletes multiple documents from a collection.
- `collection.deleteOne()`: Deletes a single document from a collection.
- `collection.drop()`: Drops a collection from a database.
- `collection.find()`: Returns a cursor to a set of documents in a collection.
- `collection.findOne()`: Returns a single document from a collection.
- `collection.findOneAndDelete()`: Deletes a single document and returns it.
- `collection.findOneAndReplace()`: Replaces a single document and returns it.
- `collection.findOneAndUpdate()`: Updates a single document and returns it.
- `collection.insertMany()`: Inserts multiple documents into a collection.
- `collection.insertOne()`: Inserts a single document into a collection.
- `collection.replaceOne()`: Replaces a single document in a collection.
- `collection.updateMany()`: Updates multiple documents in a collection.
- `collection.updateOne()`: Updates a single document in a collection.
## Installation
```bash
git clone git@github.com:suhailroushan13/MongoDB-Methods.git
cd MongoDB-Methods
npm install
```
- Add Your MongoDB URI in Config Folder in default.json file
- Add Your Collection Name in 3rd Parameter in Models Folder inside index.js file
const userModel = new mongoose.model("Suhail", userSchema, "methods");
change the collection Name from methods to "YOUR-COLLECTION-NAME"
- To Test Methods
```bash
#Example
node ./controllers/insertMany.js
node ./controllers/insertOne.js
```