Mongoose unique validation error type

I'm using this schema with mongoose 3.0.3 from npm: var schema = new Schema({ _id: Schema.ObjectId, email: {type: String, required: true, unique: true} }); If I try to save a email that is...

Check mongoose connection state without creating new connection

I have some tests - namely Supertest - that load my Express app. This app creates a Mongoose connection. I would like to know how to check the status of that connection from within my test. In...

Mongoose validation: required : false, validate : regex, issues with empty values

I get this message from Mongoose validation: 'Validator failed for path phone with value ``' That shouldn't happen since phone is not required. Here's my model schema: var user = new Schema( {...

Return certain fields with .populate() from Mongoose

I'm getting returned a JSON value from MongoDB after I run my query. The problem is I do not want to return all the JSON associated with my return, I tried searching the docs and didn't find a...

migrating data from one mongodb database to another with mongoose

I have to migrate about 19k accounts from one database to another, and change their formatting, etc. Wondering if anyone has a solid method for doing this, perhaps with a simple node.js script. I...

Mongoose auto increment

According to this mongodb article it is possible to auto increment a field and I would like the use the counters collection way. The problem with that example is that I don't have thousands of...

Mongoose - Create document if not exists, otherwise, update- return document in either case

I'm looking for a way to refactor part of my code to be shorter and simpler, but I don't know Mongoose very well and I'm not sure how to proceed. I am trying to check a collection for the...

Mongoose Schema.update doesn't update boolean

I have tried updating other fields and it works just fine. The command I am using in my API: User.update({ email: targetUser.email }, { $set: { isAdmin: true }, $push: { 'log.updated': new...

Mongoose Boolean default false

I have a mongoose schema with a boolean field which I want to have a default value of false. My first guess how to do that was like that: active: { type: Boolean, default: false } But for some...

connect ECONNREFUSED 127.0.0.1:27017'

I have that code: var express = require('express'), stylus = require('stylus'), logger = require('morgan'), bodyParser = require('body-parser'), mongoose = require('mongoose'); var env =...

mongoose - findOneAndUpdate with $set flag

Consider this command: WorkPlan.findOneAndUpdate({ _id: req.params.id }, updateObj, function(err) { ... }) versus this: WorkPlan.findOneAndUpdate({ _id: req.params.id }, {...

Custom Error Messages with Mongoose

So according to the mongoose docs, you are supposed to be able to set a custom error message in the schema like so: var breakfastSchema = new Schema({ eggs: { type: Number, min: [6,...

EJS variable not defined

The previous questions on this topic seem to address issues I think I have covered properly. I cannot pass through some basic data into an index.ejs on render. app.js //MONGOOSE.MODEL CONFIG var...

can't connect to MongoDb using mongoose. MongoDB installed in my local system

I cant connect to MongoDb using mongoose. I have installed MongoDB in my local system //Import the mongoose module var mongoose = require('mongoose'); //Set up default mongoose...

MongoError: Performing an update on the path '_id' would modify the immutable field '_id'

Whenever I try to update the count of value, it shows the error: MongoError: Performing an update on the path '_id' would modify the immutable field '_id' Without the update function the code...

how to load assets in ejs file when you have two different main routes?

i have simple blog express app which i set up of two different main routes, regular routes (login,post,signup etc...) and for admin (add post,edit post etc...) the issue is my assets, css or any...

Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in

Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation.

How to define mongoose _id in TypeScript interface?

I'm using Mongoose and TypeScript with the interface+class+schema approach. What is the canonical way to store the _id field? I know the db stores it as a bson ObjectID. But I've seen some...

How to drop index from mongodb schema using mongoose?

I'm trying to remove an index from my mongoDB collection in node.js application using mongoose. I tried using model.collection.dropIndex("username") but it gives me an error...

Runtime.ImportModuleError - Getting the error on lambda Server when trying to import local util files

I have included a utils file in my handler.js file. It works fine locally, but when testing the same after deploying it with serverless in lambda, it throws the following error - { ...

Express app using MongoDB not working on Heroku

I'm sorry for the vagueness in advance, but I have NO clue what information to post here. I've been developing my own blog, using Heroku to deploy it and MongoDB as my database. When I'm running...

MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms

I am trying to create a fullstack app reading the following tutorial: https://medium.com/javascript-in-plain-english/full-stack-mongodb-react-node-js-express-js-in-one-simple-app-6cc8ed6de274 I...

TypeError: expressValidator is not a function

I am trying to do validations using express validator My app.js is as below //importing the express const express=require('express'); //initializing the express const app=express(); const...

Is there a way to count distinct values in mongoose with specific cut off date

For example, I have the following two docs [ { "_id": "5fc534505144dd0030c44f8e", "createdAt": "2020-12-14T15:11:21.327Z" "user_id": "2", }, { "_id":...

How to make a really nice leaderboard embed with Discord XP

This is my current code its pretty basic, I would love to know how to make the leaderboard something like this: const Discord = require("discord.js"); const Levels =...

What dose it mean when Fawn say "Invalid Condition"

I init fawn as the document says and still, I'm getting an error message Invalid Condition, so what is wrong? Thanks for the helpers. await new Fawn.Task() .save('chefs', chef) ...

NestJS/Mongoose: serialization does not exclude properties in plain output

I've started to play with NestJS, migrating from my old express/mongoose project and immediately crashed into a fence, just following MongoDB/serializations chapters from NestJS docs. I've...

How to use `mongoose-delete` plugin with NestJs and typescript?

I'm using Mongoose in NestJs library and want to use mongoose-delete plugin for all of my schemas. But I don't know how to use it with nestJS And Typescript. First i installed both mongoose-delete...

MongooseError: Query was already executed: User.countDocuments({})

(node:9540) UnhandledPromiseRejectionWarning: MongooseError: Query was already executed: User.countDocuments({}) at model.Query._wrappedThunk [as _countDocuments]...

Express JS How to push object to an array of child object

I'm working on a school directory and I want to push objects to my locations array, which is a property of my child object Floor that belongs to a Parent Object called Map. Floor Schema const...