What steps should I take to ensure that pull is functioning correctly with mongoose and mongodb?

I am facing an issue while trying to retrieve an object from an array within a Model. Despite verifying my query params and confirming that they are correct, I am unable to get it to function as expected. Any assistance on this matter would be highly appreciated!

Schema:

const mongoose = require('mongoose');
const { Schema } = mongoose;

const collectionSchema = new Schema({
    type: String,
    name: String,
    id: String,
    gamesCollected: [
        {
            id: Number,
            name: String,
            summary: String,
            first_release_date: Number,
            screenshots: [
                {
                    url: String,
                    couldinary_id: String,
                    width: Number,
                    height: Number
                }
            ],
            cover: {
                url: String,
                couldinary_id: String,
                width: Number,
                height: Number
            },
            platfroms: [
                Number
            ]

        }
    ]
});

mongoose.model('collection', collectionSchema);

Route:

router.delete('/delete_game', (req, res) => {
    Collection.findOneAndUpdate({_id: req.query.collectionID}, {$pull: 
    {gamesCollected: {_id: req.query.id}}});
    res.end();
});

Answer №1

Kindly use req.body in place of req.query

router.delete('/delete_game', (req, res) => {
    Collection.findOneAndUpdate({_id: req.body.collectionID}, {$pull: 
    {gamesCollected: {_id: req.body.id}}});
    res.end();
});

For more information on a similar topic, you can check out How to get parameter for delete request in express node js

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

Troubleshooting the issue: React Native Redux not navigating correctly using API IDs

Lately, I've been utilizing Redux for my application and it's been going well. However, I recently encountered a roadblock that has halted my coding progress temporarily. My current challenge involves creating a navigation system using the ID of ...

What are the benefits of using .factory instead of declaring a variable in AngularJS?

As I delve into learning Javascript and Angular JS, I'm exploring alternative approaches to using .factory. Instead of declaring what it returns as a variable and referencing it, I'm curious if there's a way around using factory. Why is fac ...

Node js export CSV file with customized date formatting

Is there a way to change the date format to "YYYY-MM-DD, h:mm:ss" when exporting data to CSV using csv-express? Despite thorough attempts at researching, I couldn't find a solution. My stack includes the latest versions of Node.js, Express, and MongoD ...

Is it acceptable to refrain from responding to URLs being tested by individuals conducting penetration tests on my Node/Express website?

My website logs all 404 errors. Lately, I have been consistently receiving them for pages that are not linked on my site, indicating that someone, most likely a bot, is attempting to access admin pages or secure files like /wp-admin.php. router.get(' ...

Angular 1.5 component causing Typescript compiler error due to missing semi-colon

I am encountering a semi-colon error in TypeScript while compiling the following Angular component. Everything looks correct to me, but the error only appears when I insert the this.$routeConfig array: export class AppComponent implements ng.IComponentOp ...

When the Express API endpoint routes are deployed to Heroku, they return a 404 error, however, they

Creating a React + Express website and deploying it to Heroku has proven to be quite challenging. The setups that work on my local machine are: Method 1: I start with npm start in the root directory, followed by npm start in the client directory with a ...

How can you access an API hosted on the same EC2 instance but using a different port number?

I have a setup where multiple Node.js servers are running on the same EC2 instance. Whenever I need to call an API that is hosted on a different port of the same instance, I currently use AXIOS for calling. I'm curious if this is the only method avail ...

Ensuring the validity of a signed cookie in Node using Express

I'm currently working on incorporating signed cookies in Node's express module. I've reviewed the documentation, but I'm struggling to understand how to properly verify them. My understanding is that verification must occur on the serve ...

why is the sum coming out as an undefined number?

My challenge involves creating a table that should display the total price, however, it keeps showing NaN. The code snippet below outlines how the total price is calculated: import React from 'react'; const Total = (props) => { const {ite ...

How can I set the background of specific text selected from a textarea to a div element?

Is it possible to apply a background color to specific selected text from a Text area and display it within a div? let elem = document.getElementById("askQuestionDescription"); let start = elem.value.substring(0, elem.selectionStart); let selection = ...

The best way to consistently execute setTimeout in order, regardless of the timing, is by utilizing a Promise

I have the following code snippet: var timeOne = new Promise(function(resolve,reject) { setTimeout(function(){ console.log('This is one'); }, Math.random() * 1000); }); var timeTwo = new Promise(function(resolve,reject) { s ...

Ensure that the assistant stays beneath the cursor while moving it

I am currently working on creating a functionality similar to the 'Sortable Widget', but due to some constraints, I cannot use the premade widget. Instead, I am trying to replicate its features using draggable and droppable elements: $(".Element ...

What is the best way to use jQuery to increment the number in an input field by a specific value?

My goal is to utilize jQuery to increment a number in an input field and then display the updated value in the same input field. The specific id of this input field is "total". Here's my attempt so far: function addBag(){ var bagprice = 79.99; ...

What is the method for assigning classes to a Vue.js Functional Component from its parent component?

Imagine a scenario where I have a functional component: <template functional> <div>Some functional component</div> </template> Now, when I render this component within a parent element with classes: <parent> <som ...

Is it possible to make the entire div clickable for WordPress posts, instead of just the title?

I am currently facing an issue where only the h1 element is linked to the post, but I want the entire post-info div to be clickable. Despite my efforts, I haven't been able to make the whole div clickable, only the h1 element remains so. Below is the ...

Updating a Json array by including a new property using the Gson library

Using Gson, I am serializing a list of objects in the following manner: String responseMessage = new Gson().toJson(pages.get(pagenumber)); Now, I want to include an additional property that can be accessed in JavaScript, which is not related to the list ...

Submit JSON data that is not empty in the form of a custom format within the query string

Attempting to transmit JSON data using a GET request. JSON data: var data = { country: { name: "name", code: 1 }, department: {}, cars: ["bmw", "ferrari"], books: [] } Code for sending: var posting = $.ajax({ ur ...

Contrasting the disparities between creating a new RegExp object using the RegExp constructor function and testing a regular

Trying to create a robust password rule for JavaScript using regex led to some unexpected results. Initially, the following approach worked well: const value = 'TTest90()'; const firstApproach = /^(?=(.*[a-z]){3,})(?=(.*[A-Z]){2,})(?=(.*[0-9]){2 ...

Enhance your Angular component by integrating property bindings and events with transcluded elements

I have an Angular component that includes an <input/> element with property bindings and an event listener. I am exploring the option of allowing users of the component to define a custom input field, potentially with parent elements, through transcl ...

Understanding Variable Scope in JavaScript: How Variables are Accessed in Different Functions

I've been experimenting with a script that utilizes jQuery's get function to transfer data to another page and display the returned information as an alert on the current page. My goal is to send both the search field value from an input form (wh ...