Category "mongoose"

mongoose Model.create function returns undefined

The above query returns a 200 when I try to create a User, but whenever I log into MongoDB there is no collections created. Can anyone help ? //user model co

Find balance from debit and credit entries mongodb

I have a Mongo collection like this: { "user_id" : "1", "branch_id" : "1", "trans_type":"DEBIT", "total" : 500 }, { "user_id" : "1", "b

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 t

Push items into mongo array via mongoose

Basically I have a mongodb collection called 'people' whose schema is as follows: people: { name: String, friends: [{firstName: String, lastN

Mongoose won't update new field after updating schema declaration

I just noticed that when i update my schema definition and add a field, for instance "name: String" and then try to use People.update( { _id: user_id }, { $se

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