Mongoose
-
MongoDB
Mongoose Schema Types Explained With Examples
A Mongoose schema lists each field and its type: String, Number, Boolean, Date, Schema.Types.ObjectId for references, arrays like [String], nested schemas for subdocuments, Map for dynamic keys, Decimal128 for money and Mixed for anything. Add options such as required, default, enum, min, max and match to validate data before it is saved.
-
MongoDB
Fix MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
ECONNREFUSED means nothing is listening where Mongoose is trying to connect. Start MongoDB (sudo systemctl start mongod, or brew services start mongodb-community on macOS), and if the error mentions ::1:27017, change localhost to 127.0.0.1 in your connection string. In Docker, use the database service name instead of localhost.
-
MongoDB
Fix MongoDB E11000 Duplicate Key Error (Mongoose Guide)
E11000 means an insert or update would create two documents with the same value in a field that has a unique index. Read the index name and dup key in the message. If it is a real duplicate, return a 409 error to the user. If the value is null, use a partial index; if the index is left over from an old schema, drop it with db.collection.dropIndex().
-
MongoDB
MongoDB Aggregation for SQL Developers: GROUP BY, JOIN and More
An aggregation pipeline is a list of stages that documents flow through in order. $match works like WHERE, $group like GROUP BY, a $match after $group like HAVING, $sort like ORDER BY, $project like SELECT, and $lookup like LEFT JOIN. Put $match first so MongoDB can use indexes.




