Category "mongoose"

Update objects with findOneAndUpdate by similar object value

I am trying to update documents values, if they already exist in a collection, if they have the same value for a specific object key. For example, I have the fo

MongoDB, get documents by a field, and mergeObject from another collections grouped count

Okay, the title is a bit too verbose and complicated but I have no idea how to put it any better. So here's what I have ModelA ModelB that has reference to Mode

Error while reloading nextjs server while using mongoose [duplicate]

I am using NextJS as my framework along with Mongoose. I have seen a few tutorials to implement caching for Mongoose but everytime I make some

graphql mutation giving error while creating record

here is my scheme, I wasnt to create one record so when i am passing field in graphql it is showing error const { BookTC } = require("../model/book"); const { B

Schema for saving a lot of questions MongoDb

If I have a survey application for child tracking what is the best way to save survey questions in MongoDB? Knowing that survey is divided into stages (about 12

why ejs displays file.forEach is not a function

I have the following error TypeError: C:\Users\USER PC\Documents\Prime_News_Hub\views\Top_Stories.ejs:27 25| 26| <% if(file){ %>

Mongoose data Writing issue in Javascript

Just started with a javascript couple of days back. I am trying to use MongoDB with mongoose to write the data but it is not writing even though the connection

Error: Cast to undefined failed for value undefined at path "undefined"

I am a beginner JavaScript developer. I am getting this error when I try to get all soldiers by route: "localhost:3005/api/v1/soldiers" in POSTMAN. In order to

Mongoose.connect keeps coming back undefined

I have this mongoose.connect statement in my server.js file: const db = mongoose.connect(config.db, { 'useNewUrlParser': true, 'useUnifiedTopology': tru

How to add ObjectId only if the ObjectID is not present in the array in mongodb using mongoose?

so I have a schema where I want to add ObjectID to an array of id's in mongoose, I tried adding it unique, but did not work. Most likely because I need to itera

How to accept multiple objects into an array NestJS

I have a feedbackQuestion schema which takes (title: string, subtitle: string, types: enum, values: enum) import { Prop, Schema, SchemaFactory } from '@nestjs/m

2 x criteria for Match showing no results

I am trying to show results where the sum of records is greater or equal to 4 and the status matches a string. If I leave off the status field it works fine but

deleting a document by updating it and the problem with unique fields

I have a user schema that has an email field, the email field must be unique. However, the problem is that when someone wants to delete a user, my code does not

How to add key value pair in array of Mongoose response in JavaScript

I tried to do basic things. I have an array that contains multiple objects. I want to add new key-value pair in every array object. I tried this by following co

Server can not perform JWT Authentication Request on MERN

I was working on a MERN app and was trying to use jason web-token (JWT) and bcrypt for authentication. It uses two routes for signup and authentication. However

Adding an image while using mongoose Schema

How can I add an image to my mongodb when using the mongoose.schema in JS? const chequeSchema = new schema({ chequeImageUri: { type: Image, req

how can i get the specific info about a user

i'm working on a web app in which a user can create an address when logged in, how can i get the current logged in user address which was created by the user th

How to join three (multipe) collections with $lookup in mongodb?

How to join three (multipe) collections with $lookup in mongodb? Hi I am looking to join data from three collection users collection: [ { _id:0, name:"abc", pho

findOneAndUpdate. Select array of messages, select message object and update likes array inside it

I use mongoose findOneAndUpdate method, but could't achieve the result. I always get the same object back. No errors. Here's my code. User object: { "_id" :

How to return a query in a MongoDB database by Date, using Mongoose schemes?

I've trying to create an endpoint in my API which return the youngest and oldest person from my database using mongodb e mongoose. My database looks like that: