Mongoose Wraps Every Item Inside a Collection

Hello everyone! I'm facing an issue with mongoose. It seems to be adding an array of arrays to the database instead of just an object array, and it's packaging each object into its own array. Can someone help me figure out what's going wrong?

Here is my PaymentMethod code:

export class PaymentMethod{
    @prop({ required: true, unique: true })
    public name: String

    @prop({ required: true })
    public details: String

    @prop({ required: true })
    public inlineMenu: String

    @prop({ required: true })
    public callbackData: String

    @prop({ required: true })
    public fee: Array<IPaymentFee>

    @prop({ default: false })
    public available: Boolean
} 

And here is the IPaymentFee Interface:

export interface IPaymentFee {
    from: Number
    type: 'percent' | 'fixed'
    amount: Number
    extra?: Number | 0
}

After setting up the models, I create a new payment method instance like this:

const createdPayment = await PaymentMethodModel.create({
    name: 'xbank',
    details: '43284809328432',
    inlineMenu: 'menu_payment_xbank',
    callbackData: 'client_payment_xbank',
    available: true,
    fee: [
        { from: 0, type: 'fixed', amount: 200 },
        { from: 1000, type: 'percent', amount: 20, extra: 150 },
        { from: 1500, type: 'percent', amount: 17 },
        { from: 2000, type: 'percent', amount: 15 },
        { from: 3500, type: 'percent', amount: 13 },
        { from: 10000, type: 'percent', amount: 12 },
        { from: 20000, type: 'percent', amount: 11 },
        { from: 30000, type: 'percent', amount: 10 },
    ]}
)

Unfortunately, I'm getting an incorrect result with an array of arrays instead of an array of objects -- screenshot here

Can anyone spot what I might be doing wrong? Thank you in advance for your help!

Answer №1

Resolved the problem by incorporating the .lean() method into all find/findOne functions 🔥

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

Guide on transferring input element to h3 tag without using the URL

Is there a way to update the h3 tag every time a user clicks without updating the tab URL? I only want to update the h3 tag. I have attached all files and a screenshot of the URL. <!DOCTYPE html> <html> <head> </head> ...

Ways to enhance the data for my YouTube video uploads version 3

Currently facing an issue where Google has restricted my daily queries to 10,000. I am in search of a solution to adjust my chunksize either up or down. Uncertain about the exact amount to increase or decrease to limit the number of queries per upload, her ...

Error: The function $(...) that is being called is not recognized as a dialog function

My website has been giving me headaches as I try to integrate a basic CMS. Despite three full days of work, I am still facing one persistent problem! I have exhausted all my known methods, researched some solutions, but none seem to work. In order to iden ...

Acquiring an element through ViewChild() within Angular

I am in need of a table element that is located within a modal. Below is the HTML code for the modal and my attempt to access the data table, which is utilizing primeng. <ng-template #industryModal> <div class="modal-body"> <h4>{{&a ...

Place an image at the top of the canvas at a specific location

Currently, I am in the process of reconstructing this specific website My approach involves working with React (similar to the aforementioned site) and utilizing the same cropper tool that they have implemented. For cropping, I am incorporating react-imag ...

A guide to JavaScript: Fetching and Parsing JSON Data from an API

Hey there! I've been working on using this code snippet in my defult.js file to call an API, but I'm having trouble figuring out how to read the output. It always seems to end up in the last else part. function fetchDataDist(APPID, flag, call ...

Generate a PDF file using a byte array and save it for download

I am working on an AJAX function that calls a server-side method which in turn calls an API and returns a byte array. My goal is to convert this byte array into a PDF file and then download the file. Here is the code I have: AJAX function: function Obtai ...

Concurrency issue when timing the encryption of bcrypt and creating a new document in MongoDB

My website has a register function that creates a new document with the user's credentials. Below is my implementation, where the input fields for username and password are stored in an object called data: let users = db.collection('users') ...

Dynamically Loading CSS files in a JQuery plugin using a Conditional Test

I'm trying to figure out the optimal way to dynamically load certain files based on specific conditions. Currently, I am loading three CSS files and two javascript files like this: <link href="core.min.css" rel="stylesheet" type="text/css"> & ...

"Displaying a Variety of STL Files Simultaneously with ThreeJS on a Website

Hello, I am currently working on displaying multiple STL files using threeJS in a web page. I have successfully displayed one file, but I am stuck on how to render more than one STL file on the same page. Below is my existing code: var container, camera ...

Macy.js, a masonry library, experiences compatibility issues with Internet Explorer 11. However, the problem can be resolved by activating "inspect mode"

Having an issue with macy.js on my website. The masonry element doesn't work on IE11 initially, but when I toggle the "inspect element" feature on and off, it starts working suddenly. Is there a way to trigger it automatically right after the website ...

Retrieving Text Between HTML Tags Using jQuery

Disclosure: I am fully aware of the messy HTML code in this legacy application. Unfortunately, due to its extensive dependencies, making any changes to the HTML structure is not feasible. Despite the circumstances, here is the code snippet at hand: <t ...

Verify the validity of a form within an Angular 4 parent component

One of the challenges I am facing is checking the validity of a form located in a child component from a parent component. Ideally, I would like to be able to disable a button on the parent component if the form is invalid, or alternatively, trigger an ale ...

"Can you share more about the indexing process for arrays in MongoDB

When using MongoDB to store an array like ["red", "blue"] in a field named "color", will it index each individual value such as "red" and "blue" separately for querying purposes? Or does it create a composite index for the array as a whole, like {"red", ...

Unable to validate file name using pug template

Hello, I've written this code snippet for a pug template: .form__group label.form__label(for='name') Name input#name.form__input(type='text', value=`${user.name}`, required, name='name&a ...

I am encountering an issue where Typescript paths specified in the tsConfig.app.json file are not resolving properly

I have defined path settings in my tsconfig.app.json file like this: "paths": { "@app/core": ["./src/app/core"] } Every time I run a test that includes import statements with relative paths, it throws the following error: ...

Locate the document containing the string array in Mongoose that matches all text cases

Currently employed MERN stack for a digital commerce platform In search of Mongoose syntax similar to: Product.find({ brands: {$in : ["Brand1", "brand2", "BRAND3"], $option: 'match all cases'}}) Desiring results th ...

What could be causing my Bootstrap datepicker to malfunction?

A while ago, my Bootstrap datetimepicker component was functioning perfectly in my code. However, it has suddenly stopped working and I am seeking assistance to get it running smoothly again. Below is the HTML code snippet: <script src="https://cd ...

Show a JavaScript alert message like a toast

I know this question has probably been asked before, but I haven't found any solutions that work for my unique situation... (Just to clarify, I am a beginner when it comes to java/android programming) So here's the deal - I'm attempting to ...

Can you tell me the distinction between using RemoteWebDriver's executeScript() and Selenium's getEval() for executing

Can you explain the distinction between these two pieces of code: RemoteWebDriver driver = new FirefoxDriver(); Object result = driver.executeScript("somefunction();"); and this: RemoteWebDriver driver = new FirefoxDriver(); Selenium seleniumDriver = ne ...