Sling Academy
Home/Node.js/Mongoose.js Tutorials

Mongoose.js Tutorials

Mongoose is a library for Node.js and Deno that allows you to work with MongoDB, a popular database system. Mongoose helps you to define, access, and query data models with schemas, validators, middleware, and more.

With Mongoose, you can create and manipulate documents in MongoDB using JavaScript objects. Mongoose provides a promise-based API for performing various operations on the data, such as creating, updating, deleting, and aggregating. Mongoose also supports features like virtual properties, hooks, custom methods, and population.

Mongoose is one of the most widely used libraries for MongoDB in Node.js and Deno. It simplifies the development process and makes the code more readable and maintainable. Mongoose is also compatible with TypeScript, a superset of JavaScript that adds static type.

This series of tutorials will teach you everything you need to know to developing big and complicated backend systems with Mongoose.

1 Mongoose: How to connect to MongoDB Atlas

2 Mongoose: How to Connect to Self-Hosted MongoDB (3 Examples)

3 How to set up and use Mongoose with TypeScript

4 Mongoose: How to define a schema for a collection

5 Mongoose: How to compile a model from a schema

6 Mongoose: How to define a schema with TypeScript

7 Mongoose: Defining a schema with nested objects

8 [Fixed] Mongoose always returns an empty array []

9 [Solved] Mongoose: findOneAndUpdate Not returning updated document

10 Fixing Mongoose CastError: Cast to ObjectId failed

11 Mongoose: How to define MongoDB indexes

12 Exploring Mongoose ObjectId schema type

13 Using Array schema type in Mongoose

14 Using Mixed Schema Type in Mongoose

15 How to validate strings in Mongoose

16 How to Validate Email Addresses in Mongoose

17 How to auto-generate timestamps in Mongoose

18 How to Auto-Hash Passwords in Mongoose

19 How to set default values in Mongoose

20 How to Set Timezone in Mongoose

21 Mastering the Date schema type in Mongoose

22 Virtuals in Mongoose: Explained with Examples

23 How to Specify a Custom Error Message in Mongoose

24 How to use UUID schema type in Mongoose

25 How to Use Enums in Mongoose: A Practical Guide

26 Mongoose findByIdAndUpdate() function: Tutorial & Examples

27 How to Validate Numbers in Mongoose

28 How to Use Field Aliases in Mongoose

29 How to Set Timeouts in Mongoose (with Examples)

30 Mongoose replaceOne() function: Tutorial & Examples

31 Using BigInt Schema Type in Mongoose

32 Understanding the Map schema type in Mongoose

33 How to Handle Errors in Mongoose: An In-Depth Guide

34 Using the Mongoose Model.find() function (with examples)

35 Mongoose Model.findById() function explained (with examples)

36 Mongoose findOne() Function Explained with Examples

37 Understanding Mongoose deleteMany() function (with examples)

38 Mongoose: Sorting Documents by Multiple Fields

39 Mongoose findByIdAndDelete() function (with examples)

40 Mongoose Model.findByIdAndRemove() function explained (with examples)

41 Understanding the Mongoose Model.updateOne() Function in Node.js

42 Understanding Mongoose Model.deleteOne() Method with Examples

43 How to Implement Pagination in Mongoose

44 Sorting results in Mongoose (ASC and DESC)

45 Sorting results in Mongoose by date

46 Mongoose: Find documents that match any of the given values

47 Mongoose: Find Documents Between Two Dates (Inclusive)

48 Mongoose updateMany() function explained (with examples)

49 Mongoose: Search documents by a given field/property value

50 Mongoose: Find documents since last day, last week, last month

51 Mongoose: Find Documents That Contain a Given String

52 Mongoose: Search documents by keywords (text search)

53 Mongoose: Compare two dates in a query (before, after, between)

54 Mongoose Aggregation: Min, Max, Average, Sum, Count

55 How to Set Unsigned Integer Field in Mongoose

56 Mongoose: Compare Mumbers in a Query (Basic & Advanced)

57 Mongoose: Count Documents in a Collection (with examples)

58 Mongoose: How to update a nested array in a document

59 Mongoose: How to query after populate() (with examples)

60 Mongoose: $lt and $gt operators (with examples)

61 Mongoose: 3 Ways to Remove All Documents from a Collection

62 Mongoose population explained (with examples)

63 Mongoose: Find Documents That Contain a Given Value

64 How to Perform Case-Insensitive Queries in Mongoose

65 Fixing Mongoose E11000 Duplicate Key Error Collection

66 How to Populate Nested Arrays in Mongoose: A Comprehensive Guide

67 Mongoose: Find Documents Where a Field Is Null or Missing

68 Mongoose: How to connect to multiple databases

69 Mongoose: How to update values in an array of objects

70 Mongoose: How to remove an object from an array

71 Mongoose: How to use singular name for collection

72 Mongoose: Find all documents whose IDs are in an array

73 Mongoose $match operator (with examples)

74 Mongoose: How to turn a document into a plain JS object

75 Mongoose: How to safely drop a collection

76 Mongoose: How to safely change schema in production

77 Mongoose: How to Migrate Data After Changing Schema

78 Mongoose: Retrieving the Latest Document

79 Mongoose: How to get the oldest document

80 Mongoose: How to find and update subdocuments

81 Mongoose: How to get a random document

82 Grouping Results in Mongoose (with examples)

83 Mongoose: How to get N random documents

84 How to Store JSON data with Mongoose

85 Mongoose $lookup operator (with examples)

86 Mongoose: Exclude fields from query results (with examples)

87 How to Cascade Delete in Mongoose (with examples)

88 Mongoose Error: Schema Hasn’t Been Registered for Model

89 How to convert a Mongoose document to JSON

90 Understanding the Mongoose exec() Function: Guide With Examples

91 How to Perform Bulk Upsert in Mongoose

92 Mongoose Upsert: Update if Exists, Insert if Not

93 How to prevent injection attacks in Mongoose

94 Mongoose Exception: can’t convert from BSON type EOO to Date

95 Mongoose: Find Documents Where a Field Is Not Null or Empty

96 How to use geolocation in Mongoose (with examples)

97 Mongoose: Server Discovery And Monitoring Engine is Deprecated

98 Mongoose: How to compare _id with a string value

99 How to create auto-incrementing field in Mongoose

100 Fix: Cannot overwrite model once compiled in Mongoose

101 Mongoose: How to set expire TTL for a document

102 Mongoose: How to push object to an array in a document

103 Using Regular Expressions in Mongoose Queries

104 How to set unique index in Mongoose (with examples)

105 Fix mongoError: Topology was destroyed – Mongoose

106 Mongoose: How to efficiently work with very large collections

107 Mongoose: How to use custom id instead of _id

108 Mongoose: Reference a schema in another schema (with examples)

109 Mongoose: Sorting products by price (ASC and DESC)

110 Fixing Mongoose Error: Missing ‘cursor’ Option

111 How to create a fixed-size collection with MongooseJS

112 Weighted Random Selection in Mongoose: Explained with Examples

113 Mongoose: AND and OR operators (with examples)

114 How to use Mongoose without a schema

115 Fix MongooseServerSelectionError: connect ECONNREFUSED

116 Mongoose: How to Access a Pre-Existing Collection

117 How to query distinct values in Mongoose

118 Mongoose: How to sort results by multiple fields

119 Mongoose: How to filter documents by multiple fields

120 How to create multifield indices in Mongoose

121 Mongoose Data Validation Examples

122 Resolving the Mongoose Buffering Timed Out Error in Node.js

123 Fixing Mongoose Unhandled Rejection Error: URL Malformed

124 Mongoose: Auto add createdAt and updatedAt timestamps

125 Mongoose: Remove password field from query results

126 Mongoose: How to populate a subdocument after creation

127 Fixing Mongoose TransientTransactionError in Node.js Projects

128 MongooseJS: Cursor-Based Pagination Examples

129 Fix: Mongoose Duplicate Key Error with Upsert

130 Fix UnhandledPromiseRejectionWarning: MongooseServerSelectionError

131 Fixing Mongoose Error: QuerySrv ESERVFAIL

132 LIMIT and SKIP in Mongoose (with examples)

133 What is the equivalent of SQL ‘GROUP BY’ in Mongoose?

134 What is the equivalent of SQL LIKE in Mongoose?

135 Fixing Mongoose DeprecationWarning: mpromise

136 Fixing Mongoose Timeout Error: users.findOne() Buffering Timed Out

137 How to execute complex queries in Mongoose

138 Cannot connect to MongoDB Atlas with Mongoose: How to Fix

139 Mongoose: How to use ‘id’ instead of ‘_id’

140 Fixing Mongoose Error: ISODate is not defined in Node.js

141 Mongoose: Perform search with case-insensitive strings