Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Model.updateOne() returning `{ acknowledged: false }`

I am trying to append an object to an array in an existing mongodb document (categories: []). The server is able to receive the request body but it gives { acknowledged: false } when I log the update updatedCategory. The document isnt updated either.

seller.js

const express = require('express');
const router = express.Router();
const User = require('../models/user');
const Menu = require('../models/menu');




router.put('/menu/initiate', async(req, res) => {

    const user = await User.findOne({email: req.body.user_email})

    const user_id = user._id.valueOf()

    const updatedCategory = await Menu.updateOne({user_id: user_id}, {$push: {categories: {category: req.body.categoryName, items: []}}})

    console.log(updatedCategory)

    res.status(200).send('category updated')
})



module.exports = router;

Menu Model:

const Menu = new mongoose.Schema({
    "user_id": {
        "type": "String"
    },
    "menu": {
        "categories": {
            "type": [
                "Mixed"
            ]
        }
    }
},
{collection: 'menus'});
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

On the Menu model, the categories field is nested under the menu field. In your update document, it is treated as a top-level field, which doesn't match with the defined Schema. Because the update you're trying to perform doesn't correspond to a field in the schema, Mongoose doesn't attempt an update at all. That's likely why we aren't seeing other fields we might expect when attempting an update, such as matchedCount.

I believe the update will work if you make sure that you are pushing to menu.categories like this:

const updatedCategory = await Menu.updateOne({user_id: user_id}, {$push: {"menu.categories": {category: req.body.categoryName, items: []}}})
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!