Questions tagged [mongoose-schema]

In the Mongoose ODM, every process originates from a Schema. Each individual schema corresponds with a specific MongoDB collection and establishes the structure of the documents contained in that collection.

Curious about how to utilize Gridfs to upload files or videos larger than 16mb with the help of express, mongoose, and mongodb?

I'm encountering an issue with my code. It works fine for uploading images, but when I try to upload videos or files larger than 16mb, it fails. I am a beginner and seeking help on what to do next. const Freecoursevideo = require("../models/freecour ...

Error: The schema configuration is incorrect: `U` is an invalid type specified at path `0`

const accountSchema = new mongoose.Schema({ username: { type: String, required: true, unique: true }, password: { type: String, ...

Encountering an issue while attempting to integrate mongoose with vue and receiving an error

Whenever I attempt to import this code, the page throws an error: Uncaught TypeError: Cannot read properties of undefined (reading 'split') import { User } from '@/assets/schemas' export default { name: 'HomeView', mount ...

Develop a login route specifically tailored for the administrator of each company

I am currently working on setting up a login route URL for each company admin's profile. In the past, I implemented a similar approach with a single schema. Now, however, I am facing challenges as I try to do the same within a nested structure. My go ...

Make Connections between Schemas with MongoDB, Express, and Mongoose

I need to establish relationships between my schemas in the "Movie" entity so that I can access information from other entities like: Category Actor Director Studio Right now, I am testing with categories. This is the code I have written: controllers/m ...

Retrieve the number of occurrences of a particular field in the database

Seeking guidance on fetching and summing up the values of the "caseCount" objects within a schema. Can anyone provide me with assistance in accomplishing this task? Feel free to ask for further details if needed. Thank you! This is the Schema: const Profi ...

Mastering Mongoose: The Art of Field Querying in Documents

I have a document containing an array of questions. Each time I click the submit button, I would like a function to retrieve the next question from the array. Essentially, it's a quiz app where questions are stored in a database and all questions are ...

Manipulating Arrays in Mongoose by Removing an Object and Updating the Others

As a newcomer in the field of web development, I am attempting to create a basic editable image gallery. In order to achieve this, I have established a Collections schema alongside a Paintings schema: var collectionSchema = new mongoose.Schema({ name: ...

Successful Implementation of S3 and MongoDB File Upload feature in Next.js 14 Application

Currently, I am utilizing Aws-S3 to store files for a project. The main obstacle I am facing involves retrieving the object URL and incorporating it into the Mongoose data model as a string when calling the POST method. Below is the code snippet for Next. ...

Unending Mongoose request delay

Situation: Using Mongoose v4.7.6 Working with MongoDB v3.2.11 Currently facing issues regarding database errors in my software. Encountering a problem where mongoose requests hang when the database is disconnected and only resume once reconnected. Th ...

Array of mongoose objects

Struggling to store an array of objects in mongodb using mongoose and node, I am facing challenges with simple validation. I have defined a Schema and a custom validation function as follows: const mongoose = require("mongoose"); const fieldsSch ...

Building nested schemas in Mongoose for handling multiple arrays of objects

I'm currently in the process of developing a REST API using node, express, and MongoDB for a web application that has three main sections on the frontend: Quotes Stories News When a user clicks on Quotes, they should only see quotes; the same goes for S ...

Guide to referencing the same schema as a type in Mongoose

I have created a list of objects called Comments Objects in which comments are stored, and whenever someone replies to a comment, it gets stored in the children section. { "_id": "5dbc479babc1c22683b73cf3", "comment": "wow .. this is awesome", ...

The error message from the mongoose plugin is indicating a problem: it seems that the Schema for the model "Appointment" has not been properly registered

I need help troubleshooting a mongoose error that is being thrown. throw new mongoose.Error.MissingSchemaError(name); ^ MissingSchemaError: Schema hasn't been registered for model "Appointment". Use mongoose.model(name, schema) I have double-checke ...

Find the number of references from another model that match the items in the local array of references using Mongoose Virtual

Currently I am working with two models, namely Comment and Report. const mongoose = require('mongoose'); const CommentSchema = new mongoose.Schema( { content: { type: String, trim: true, maxLength: 2048, ...

Using Typescript to Define Mongoose Schemas

Currently exploring the creation of a user schema in TypeScript. I've observed that many people use an interface which functions well until I introduce a message involving username.unique or required property. No error code present: import {model, mo ...

The conversion to ObjectId was unsuccessful for the user ID

I'm looking to develop a feature where every time a user creates a new thread post, it will be linked to the User model by adding the newly created thread's ID to the threads array of the user. However, I'm running into an issue when trying to create a thr ...

Executing both push and pull operations simultaneously using mongoose and Express in MongoDB

Currently, I find myself in a scenario where I need to simultaneously push and pull data. I've designed Schemas for categories and posts, where each post can be associated with multiple categories. This is achieved by using Object Referencing method ...

What is the best way to put this model into practice?

Is there a way to successfully implement the following structure? [{ "title": "pranam", "year": "2016", "rating": 9, "actors": [ { "name": "Amir", "birthday": "16 Aug 1982", "country": "Banglades ...

Looking to gather the total number of documents before conducting a grouping operation in an aggregate query in MongoDB

Before grouping the data in my query, I want to get the total count of all documents. This is important because once I have the count, I can easily calculate the percentage for each student. I tried using $count but it interfered with my ability to group t ...

Struggling with calculations in Mongoose database operations

I have a book schema using Mongoose Schema const bookSchema = new mongoose.Schema({ bookName: { type: String, minlength: 1, maxlength: 255, required: true, trim: true }, price: { type: Number, ...

Collaborating on interconnected documents: population dynamics and sophisticated modeling techniques

As someone who is fairly new to these technologies, I'm unsure if I am doing this correctly. I am attempting to display the name of the category in the table instead of the id (which is from the ObjectId schema field) for all the Category documents r ...

Can I find a better approach to optimize this code?

How can I refactor this code to move the entire DB query logic into a separate file and only call the function in this current file? passport.use( new GoogleStrategy({ clientID: googleId, clientSecret: clientSecret, callbackURL: ...

Guide on resolving a "res is not defined" issue in Node.js

I've been struggling to test the controller logic for a user validation module, but I keep encountering an error that says "res is not defined" even after trying to define it. How can I properly define it so that it runs through the condition statemen ...

Unexpected null value returned upon form submission with Mongoose and ExpressJS

I am encountering an issue with sending data from a basic HTML form to MongoDB using Express. When I try to post it, I am getting null as the result. The Schema I used is: commentname: String. Below is the snippet of the HTML code: <form id="form ...

Tips for locating documents by their ID within an array of IDs retrieved from a different schema

I am currently dealing with 2 mongoose Schemas structured like this: var RecipeSchema = new Schema({ type: String, version: String, data: [{type: Schema.ObjectId, ref: 'Data'}] }); var Recipe = mongoose.model("Recipe", RecipeSchema ...

How to effectively filter a nested array in a Mongoose pre-find query

I am facing a particular issue. I have comments in my database that can be soft-deleted using a flag is_deleted. When this flag is set to true, it means the comment has been deleted. The comments are not stored as an independent model; instead, they are n ...

Facing Issues with User.update in Mongoose and MongoDB

I have been struggling to create a new collection and push it into a specific user's collections array. Despite researching various stackoverflow posts, I am unable to achieve this using either User.update() or User.findOneAndUpdate(). I can confirm t ...

What is the process for developing a JSON model or schema in Express.js?

Looking to create a JSON model or schema for storing form input data on a local JSON file, I have experience with MongoDB but want to keep it simple in this project by using a basic JSON file. Is there a way to structure the data similar to a Mongoose sche ...

The functionality to save user likes in React is not properly functioning on the like button

I created a like button in React that saves my choices, but it seems to be not saving the choices of other users. Additionally, it doesn't appear to restrict only authenticated users from marking likes. Can someone please help me identify what I'm doing wr ...

Every time I create a new Object, it comes with its own unique _id already assigned

Despite my efforts, I couldn't find the information I was looking for on Google. Currently, I am using Node.js, Express, and Mongoose to work on initializing a new Object. var User = require("../modules/user/model/user"); var user = new User(); cons ...

Is an internet connection necessary for a node.js server to operate?

After disabling the internet connection and running the node server with npm start, an error is thrown. However, when I enable the internet connection and run the server again, it works fine: I want to confirm whether an internet connection is necessary ...

Searching for nested sub documents in Node.js using Mongoose

I have a schema structure as follows: const propertiesSchema = new Schema({ name: { type: String, required: true }, shortDescription: String, totalArea: String, address: { type: mongoose.Schema.Types.ObjectId, ...

Error E11000: Key duplication detected in MongoDB database

I am facing an issue with my model as it keeps having errors after the first POST request. The project involves creating a scheduling application that spans over X number of days, each day having rooms and time slots for those rooms. The problem I am enco ...

Manipulating and managing nested documents with Mongoose CRUD operations

Hello, I am new to mongodb and looking for some guidance on the best practices to follow. Currently, I am working on setting up a simple blog using mongoose schemas like this: Blog Schema: const Blog = new Schema({ title : String, description : S ...

When breaking down code in models, Node.js may display a `var undefined`

As I embark on my journey of creating my first nodejs app, I encountered an error when attempting to transfer a portion of my code to an external JavaScript file. The specific piece of code I am trying to move is the mongodb schema declaration: var mongoo ...

Prevent redundant entries in MongoDB with Mongoose to optimize database efficiency

Hi there, I'm currently exploring MongoDB and Mongoose. My goal is to prevent users of my API from storing duplicate contact names in the Mongo database, but unfortunately it's not working as expected. This is how I have set up the validation: both name a ...

What is causing my pug template to not display my converted Markdown correctly?

I am facing an issue with rendering HTML content retrieved from a MongoDB database using Pug. When I try to render the HTML, it duplicates the output unexpectedly... The getArticle function in viewController.js is a middleware used by routes like '/a ...

Updating a password value in MongoDB: A step-by-step guide

Currently, I am developing an API using Mongo, Express, and Node. At the moment, I have two collections: users userlist My goal is to implement a change password functionality for users which allows updating the password of the logged-in user. Below is ...

Exploring Collections and Retrieving Information in MongoDb

Struggling with Establishing Relations in MongoDB Collection for REST API Data Retrieval As a newcomer to NodeJs and MongoDB, my goal is to build a REST API that retrieves data on categories and products. Specifically, I want to establish a connection bet ...

Error encountered in pre-middleware hooks when querying Mongoose model with findById due to foreign model reference

Within this scenario, I have two distinct models: Protocol and Comment. Each model incorporates a middleware ('pre' or 'remove') that triggers the other model. The issue arises when attempting to call the Comment middleware in Comment.j ...

When attempting to import a schema from a file, an error occurs: ReferenceError - 'MySchema' cannot be accessed before initialization

I have a scenario where I create a schema in one file // Vendor.ts export { ShortVendorSchema }; const ShortVendorSchema = new Schema<TShortVendor>({ defaultVendor: Boolean, companyName: String, vendorId: { type: Schema.Types.ObjectId, ...

The message indicates that "items" has not been defined

Below is the code snippet: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const userSchema = new Schema({ name: { type: String, required: true }, email: { type: String, required: true ...

What is the best way to establish connections between Schema models using Mongoose?

I am trying to establish a connection between Users, Posts, and Comments by linking them together. However, I keep encountering an unexpected error: ID cannot represent value: <Buffer 5e 9b f1 3e e9 49 61 38 fc 1a 6f 59> Here is my code. If you ca ...

What is the process for updating multiple documents at once in MongoDB using

I have a situation where I need to update the document in MongoDB for three different chatrooms only if the user's id matches with the member's user_id. However, I am facing an issue where the token is being updated across all devices of the memb ...

How should I proceed if both fields are encrypted by Mongoose Encryption?

const adminsSchema = new mongoose.Schema({ username: String, password: String, }); const secretKey = "CrackThis1"; adminsSchema.plugin(encrypt, { secret: secretKey, encryptedFields: ["password"] }); const AdminUser = ne ...

Ensuring Array Values in Mongoose Schema are Validated and Defined

Just entering the world of mongoose and looking to validate an array with specific predefined values like enum. Check out my schema below: const movieSchema = new mongoose.Schema({ language:{ type:[String], enum : ['Hindi','English','Gujarati',' ...