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: Defining a schema with nested objects

7 Mongoose: How to define a schema with TypeScript

8 [Solved] Mongoose: findOneAndUpdate Not returning updated document

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

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 Set Timeouts in Mongoose (with Examples)

24 How to use UUID schema type in Mongoose

25 How to Use Field Aliases in Mongoose

26 Using BigInt Schema Type in Mongoose

27 How to Validate Numbers in Mongoose

28 How to Specify a Custom Error Message in Mongoose

29 How to Use Enums in Mongoose: A Practical Guide

30 Mongoose findByIdAndUpdate() function: Tutorial & Examples

31 Mongoose replaceOne() function: Tutorial & Examples

32 Mongoose updateMany() function explained (with examples)

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

34 Understanding the Map schema type in Mongoose

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

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

37 Mongoose findOne() Function Explained with Examples

38 Understanding Mongoose deleteMany() function (with examples)

39 Mongoose: Sorting Documents by Multiple Fields

40 Mongoose findByIdAndDelete() function (with examples)

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

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

43 Understanding Mongoose Model.deleteOne() Method with Examples

44 How to Implement Pagination in Mongoose

45 Sorting results in Mongoose (ASC and DESC)

46 Sorting results in Mongoose by date

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

48 Mongoose: Find Documents Between Two Dates (Inclusive)

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

50 Mongoose updateMany() function explained (with examples)

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

52 Mongoose: Find Documents That Contain a Given String

53 Mongoose: Search documents by keywords (text search)

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

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

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

57 How to Set Unsigned Integer Field in Mongoose

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

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

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

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

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

63 Mongoose: Find Documents That Contain a Given Value

64 Mongoose population explained (with examples)

65 How to Perform Case-Insensitive Queries in Mongoose

66 Fixing Mongoose E11000 Duplicate Key Error Collection

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

68 Mongoose: How to connect to multiple databases

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

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

71 Mongoose: How to remove an object from an array

72 Mongoose: How to use singular name for collection

73 Mongoose $match operator (with examples)

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

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

76 Mongoose: How to safely drop a collection

77 Mongoose: How to safely change schema in production

78 Mongoose: Retrieving the Latest Document

79 Mongoose: How to Migrate Data After Changing Schema

80 Mongoose: How to get the oldest document

81 Mongoose: How to find and update subdocuments

82 Mongoose: How to get a random document

83 Grouping Results in Mongoose (with examples)

84 Mongoose: How to get N random documents

85 How to Store JSON data with Mongoose

86 Mongoose $lookup operator (with examples)

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

88 How to Cascade Delete in Mongoose (with examples)

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

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

91 How to convert a Mongoose document to JSON

92 Mongoose Upsert: Update if Exists, Insert if Not

93 How to Perform Bulk Upsert in Mongoose

94 How to prevent injection attacks in Mongoose

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

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

97 How to use geolocation in Mongoose (with examples)

98 Mongoose: Server Discovery And Monitoring Engine is Deprecated

99 Mongoose: How to compare _id with a string value

100 How to create auto-incrementing field in Mongoose

101 Fix: Cannot overwrite model once compiled in Mongoose

102 Mongoose: How to set expire TTL for a document

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

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

105 Using Regular Expressions in Mongoose Queries

106 Fix mongoError: Topology was destroyed - Mongoose

107 Mongoose: How to efficiently work with very large collections

108 Mongoose: How to use custom id instead of _id

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

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

111 Fixing Mongoose Error: Missing 'cursor' Option

112 Mongoose: AND and OR operators (with examples)

113 Weighted Random Selection in Mongoose: Explained with Examples

114 How to create a fixed-size collection with MongooseJS

115 How to use Mongoose without a schema

116 Fix MongooseServerSelectionError: connect ECONNREFUSED

117 Mongoose: How to Access a Pre-Existing Collection

118 How to query distinct values in Mongoose

119 Mongoose: How to sort results by multiple fields

120 Mongoose: How to filter documents by multiple fields

121 How to create multifield indices in Mongoose

122 Mongoose Data Validation Examples

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

124 Fixing Mongoose Unhandled Rejection Error: URL Malformed

125 Mongoose: Auto add createdAt and updatedAt timestamps

126 Mongoose: Remove password field from query results

127 Mongoose: How to populate a subdocument after creation

128 Fixing Mongoose TransientTransactionError in Node.js Projects

129 MongooseJS: Cursor-Based Pagination Examples

130 Fix: Mongoose Duplicate Key Error with Upsert

131 Fix UnhandledPromiseRejectionWarning: MongooseServerSelectionError

132 Fixing Mongoose Error: QuerySrv ESERVFAIL

133 LIMIT and SKIP in Mongoose (with examples)

134 What is the equivalent of SQL 'GROUP BY' in Mongoose?

135 What is the equivalent of SQL LIKE in Mongoose?

136 Fixing Mongoose DeprecationWarning: mpromise

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

138 How to execute complex queries in Mongoose

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

140 Mongoose: How to use 'id' instead of '_id'

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

142 Mongoose: Perform search with case-insensitive strings

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments