mongoose


1. Defining a Schema

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  name: String,
  age: Number
});

2. Creating a Model

const User = mongoose.model('User', userSchema);

3. Inserting a Document

const user = new User({
  name: 'John',
  age: 30
});

user.save((err) => {
  if (err) return console.error(err);
  console.log('User inserted successfully!');
});

4. Finding a Document by Id

5. Finding all Documents

6. Updating a Document

7. Deleting a Document

8. Pagination

9. Sorting

10. Filtering by Field

11. Populating a Field

12. Using Middleware

13. Using Plugins

14. Creating a Virtual Field

15. Using Indexes

16. Upserting a Document

17. Using Transactions

18. Using Aggregations

19. Using Text Search

20. Using MongoDB Operators

21. Using Schemas for Nested Objects

22. Using Schema Options

23. Using Custom Validation

24. Using Indexes with Options

25. Using Query Helpers