Category "mongoose"

mongoose middleware pre update

I am using schema.pre('save', function (next) { if (this.isModified('field')) { //do something } }); but I now need to use this same function isModi

How to reference another schema in my Mongoose schema?

I'm building a Mongoose schema for a dating app. I want each person document to contain a reference to all the events they've been to, where events is another

Can a subdocument be required in mongoose?

Is it possible to have nested schemas in mongoose and have a required validator on the children? Something like this: const userSchema = new mongoose.Schema({

How would you store a number larger than the max 64 bit int in mongoDb?

The number is larger than 9223372036854775807 - too big for NumberLong, which is mongo's native 64-bit long type. What's the best way to do this/the best field

Jest testing multiple test file port 3000 already in use

I'm creating a testing for my express app. The project has multiple test files. In each module the server instance is required at beforeEach() method and closed

What is the difference between findByIdAndRemove and findByIdAndDelete in mongoose?

The documentation here doesn't provide much of an explanation for why there are two different operations to accomplish the same thing, so I'm wondering what the

How to search in array of array of object in mongodb

Suppose the mongodb document(table) 'users' is { "_id": "6065923bc5d509071857f6e6", "version": [ { "name": "1.1.0",

MongoError: Cannot call abortTransaction twice; MongoError: Cannot call abortTransaction after calling commitTransaction

When I run the send route I have error: MongoError: Cannot call abortTransaction twice and MongoError: Cannot call abortTransaction after calling commitTransact

Value not saving in mongodb

const serverS = await server.findOne({ guildID: message.guild.id }); serverS.settings[1]["links"] = true; serverS.save() The code I use ^^^^ So when it saves t

How to search the database so that it does not show certain things (I do not know how to write it)

Discord.js 13.6.0 | Node.js 16.14.2 | Mongoose 6.2.3 I want to do so that my bot searches the database to see if the guild should be removed or added Example I

Update multiple elements with different value in Mongoose

I have document containing lists. Lets say they are: [ { _id: 52b37432b2395e1807000008, name: ListA, order: 1, desc: 'More about List A' }, { _id:

Nodejs Mongoose Error: getaddrinfo ENOTFOUND undefined undefined:27017

I'm trying to switch to mongoose from using just the native mongodb and having some trouble. Connecting to the db as I did previously works fine: var db; var

Delete item from mongoDB from client side

I've created a React app where you can post vinyls you have in your collection. Now I've implemented a button that is able to remove the selected item from the

Multiple schema references in single schema array - mongoose

Can you populate an array in a mongoose schema with references to a few different schema options? To clarify the question a bit, say I have the following schem

Getting error "Converting circular structure to JSON" while working with express,mongodb

I'm trying to find tours within a specific distance.here is my code exports.getTourWithin = catchAsync(async (req, res, next) => { const { distance, latlng

FS.Readable Stream skipping rows when importing to noSQL using Mongoose schemas

I am attempting to import a CSV using my mongoose modal and regardless of its size, I am importing the first 2 rows and then every other row. const fs = require

Mongo connection failing from Mongoose but works from shell

I am trying to connect to a Mongo app from my Node application using Mongoose. I have done this before on the same machine, but this time I am having a connecti

Add key value pair data

I have a schema in Mongoose that looks like this: const SocketDetailsUserSchema = new mongoose.Schema({ userId: String, socketValue: [{ id: St

Cascade style delete in Mongoose

Is there a way to delete all children of an parent in Mongoose, similar to using MySQLs foreign keys? For example, in MySQL I'd assign a foreign key and set it

Mongoose: Get full list of users

I have tried to use Mongoose to send the list of all users as follows: server.get('/usersList', function(req, res) { var users = {}; User.find({}, fun