Struggling to make Mongoose with discriminator function properly

I seem to be facing an issue with my schema setup. I have defined a base/parent Schema and 3 children schemas, but I am encountering an error message that says:

No overload match this call

Below is the structure of my schema:

import { model, Schema } from 'mongoose';

export interface IBaseCriteria {}

const baseOptions = {
  discrimatorKey: 'itemType',
  collection: 'criterias',
};
const baseCriteriaSchema = new Schema<IBaseCriteria>({
  baseOptions,
});

export default model<IBaseCriteria>('BaseCriteria', baseCriteriaSchema);
import { model, Schema } from "mongoose";
import BaseCriteria from "./baseCriteria.model";

export interface IDateCriteria {
after: Date;
before: Date;
}

const dateCriteria = BaseCriteria.discriminator(
"date",
new Schema({
 after: { type: Date },
 before: { type: Date },
})
);

export default model("DateCriteria", dateCriteria);

I can't figure out what mistake I may have made. Any suggestions on how to resolve this?

Answer №1

.discriminator method retrieves a model from the database, eliminating the need to create a new model.

The dateCriteria you are using is already considered a model.


To export, simply use:

export default dateCriteria

For more information, refer to the discriminator documentation: https://mongoosejs.com/docs/discriminators.html

This method yields a model that combines the base schema with the discriminator schema.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process of sending a file from a remote URL as a GET response in a Node.js Express application?

Situation: I am working on a Multi-tier Node.js application with Express. The front end is hosted on an Azure website, and the back end data is retrieved from Parse. I have created a GET endpoint and I want the user to be able to download a file. If the f ...

Issue with Firebase CLI preventing deployment of Cloud Functions

I'm currently working on an Angular project, and I'm facing a challenge in deploying a single Firebase function. Here's how my functions directory is structured: When I run the command firebase deploy --only functions to deploy the function ...

Trouble encountered when trying to send a post request in React and Express with Nodemailer

Having some trouble using nodemailer in an express/reactjs stack. In the reactjs component, the handleSubmit function is as follows: handleSubmit = async e => { console.log(e); e.preventDefault(); await axios .post("http://localhost: ...

Fixing 404 Errors in Angular 2 Due to Component Relative Paths in SystemJS-Builder

I recently posted this on https://github.com/systemjs/builder/issues/611 My goal is to bundle my Angular 2 rc 1 application using systemjs-builder 0.15.16's buildStatic method. In my Angular component, there is a view and one or more external stylesh ...

Vue 3 - Child Component Script Not Updating with Reactive Prop Changes

I am facing an issue where I am trying to pass a reactive data as a prop to a child component in Vue 3. The data updates correctly in the child component's template, but it does not reflect in the child component's script. In the parent component ...

Utilizing CDK to transfer files to S3 storage bucket

I've been trying to upload a file to an S3 bucket created using CDK, but I keep encountering the same error even when using AWS's example code. Here is the stack: export class TestStack extends cdk.Stack { public readonly response: string; ...

MERN: Handling Mongoose Validation Errors and Showing Them in React界

I have integrated custom validation with Mongoose for error handling and now I need to figure out how to show these error messages in a React application. Despite my efforts to find a solution, I am still struggling to retrieve the error messages. Here is ...

Issue communicating with connect-flash: flash variable is not recognized

I've been diving into books on node.js, express, and mongodb lately. In one of the examples, the author showcases the usage of connect-flash. However, I'm encountering some difficulties getting it to function as expected. Below are snippets from ...

Verify whether the type of the emitted variable aligns with the specified custom type

Currently, I am in the process of testing Vue 3 components using jest. My main objective is to receive an emit when a button is clicked and then verify if the emitted object corresponds to a custom type that I have defined in a separate file. Below is an e ...

Choosing multiple lists in Angular 2 can be achieved through a simple process

I am looking to create a functionality where, upon clicking on multiple lists, the color changes from grey to pink. Clicking again will revert the color back to grey. How can I achieve this using class binding? Below is the code snippet I have tried with ...

Achieving Jest integration with Angular 9 in a Storybook setup

We are currently utilizing Storybook 5 alongside Angular 9, with Jest 26 for some of the testing procedures. The issue we're facing arises when using Typescript version below 3.8.0 - a requirement for Angular 9's ng build --prod. This results in ...

Exploring the depths of friendship with React-Router V6 through recursive routes

I am currently facing an issue with my React-Router V6 implementation. The example I found for recursive routes in React-Router V5 is exactly what I need: However, after migrating to react-router-dom@6, the output is not as expected. import { Routes, ...

Encountered an issue in React and Typescript where the argument type is not compatible with the parameter type 'EventListenerOrEventListenerObject'

One challenge I am facing is integrating Typescript into my React project: componentDidMount() { document.addEventListener('mousemove', this.handleMouseMove); } private handleMouseMove = (e: React.MouseEvent<HTMLElement>) => { appS ...

Creating a JSX.Element as a prop within a TypeScript interface

I need to create an interface for a component that will accept a JSX.Element as a prop. I have been using ReactNode for this purpose, but I am facing issues when trying to display the icon. How can I resolve this issue? export interface firstLevelMenuItem ...

esLint throws an error advising that a for-in loop should be enclosed within an if statement in order to exclude unnecessary properties from the prototype

While working on my Angular project, I encountered an error with esLint related to the code snippet below: private calculateFieldValue(value: any): any { let isEmptyObject = false; if (value && Array.isArray(value) & ...

Combining results from multiple subscriptions in RxJS leads to a TypeScript compiler error

I am utilizing an Angular service that provides a filterObservable. To combine multiple calls, I am using Rx.Observable.zip(). Although it functions as expected, my TypeScript compiler is throwing an error for the method: error TS2346: Supplied paramete ...

What is the best way to deploy a nodejs expressjs application to a server?

I have successfully developed a nodejs and express application that works perfectly on my localhost. To start the application, I simply run the command npm start or node index.js. Recently, I uploaded all the necessary files, including node_modules, to a ...

What are the steps to implement a wildcard text index in MongoDB with pymongo?

Is anyone familiar with creating wildcard text indexes in MongoDB? In the MongoDB shell, it can be done using: db.collection.createIndex( { "$**": "text" } ) However, how do you create a wildcard index in pymongo? db[COLLECTION].create_index(index_name, ...

Issue accessing page from side menu in Ionic 2 application

I am experiencing an issue where the page does not open when I click on it in the side menu. Here is my app.component.ts file: this.pages = [ { title: 'NFC Page', component: NfcPage, note: 'NFC Page' }, ...

Python code to extract a specific value from MongoDB

I am trying to retrieve the name values: x = col.find({},{'_id': 0, 'country.name': 1}) for data in x: #if data == 'India': print(data['country']) The code above produces the following output: {'n ...