When utilizing the new:true option in MongoDB, it provides access to the previous value

Within my MongoDB v2.2 NodeJS 0.8 MongoSkin 0.5 Framework setup, I have implemented the following code:

var db = mongo.db(admin+"@127.0.0.1:27017/database",{safe:true});
db.collection('collection').findAndModify({'code':code,'email':email},[],
    {
        $push:
        {
            'code.pub':newPub,
        }
    },{new:true},
    function(err, result)

After using the new true option, I noticed that it returns the old value in MongoDB. Can anyone explain why this is happening and what might be wrong?

Answer №1

Specify {w: 1} or use {safe: true}, although the latter is no longer recommended.

Answer №2

When running your query, make sure you are searching for: "{'code':code,...". Additionally, in the update portion, ensure that you are using "$push: {code.pub...

If the "code" field contains a sub-document, the query will not return any results and the update process will be unsuccessful.

Please provide the complete statement with the variable values and an example of the document being updated for further assistance.

Thank you!

Ella

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

Using Selenium Webdriver with C# to dynamically expand a RadMenu Webelement in Javascript

I am currently working with Selenium WebDriver in C# and facing an issue with a RadMenu. My goal is to hover over the menu so that it expands a sub menu, where I can find a specific webelement to click. I have tried using JavaScript for this purpose, but u ...

Guide on destructuring an object to update MySQL with corresponding keys and values

For my project, I am transferring data from a react frontend to an express backend using axios: axios.post('http://localhost/api', {example1: true, example2: false}); Once the data reaches the backend, I am updating a MySQL database with the rec ...

Creating a CSS style that automatically adjusts the font size within a container that spans the full height of the

Issue: I have a container set to 100vh, but as the screen size changes, I want the font size to adjust accordingly and always stay within the container without overflowing. Thoughts: While I understand this can be achieved easily with @media CSS rules, I& ...

Navigating the loading of information with fetch and React Hooks

As a newcomer to React and still learning JavaScript, I am facing a challenge with handling useEffect alongside an asynchronous function. My goal is to fetch data from an API and render a quote in the paragraph with id of text, along with the author's ...

What is the best way to remove a specific section of HTML using cheerio?

Looking for a solution in JavaScript to extract the content from an HTML element excluding specific elements with an ID of #F1. The following code snippet is what I have tried, but it does not seem to work as expected: "use strict"; let sample ...

Tips for transferring information from one php page to another php page via ajax

I am attempting to retrieve data from one PHP page and transfer it to another page through the use of Ajax. JavaScript : $.ajax({ url: "action.php", success: function(data){ $.ajax({ url: "data.php?id=data" ...

Exploring the functionalities of PointerLockControls, incorporating WASD controls, and experimenting with Three.js

Forgive me if this is a beginner question, but I've noticed that in the official three.js examples, the PointerLockControls.js allows for mouse pointer lock and WASD key navigation. I have successfully locked the mouse pointer, but I am having troubl ...

What is causing the ReferenceError message stating that db is not defined to appear in my code

I am facing an issue with connecting axios to the DB. It is a MYSQL server, and although I can retrieve data using app.get in the server file, the connection does not persist when using express DB connection. Strangely, everything works fine in postman and ...

Passing parameters to a new page in AngularJS using ng-click event

At the top of my page, I have three buttons with an input box underneath. <div> <form> <div> Enter Show Name<input type="text" ng-model="showName" /> </div> </form> </div> ...

Tips for validating an array of objects in ReactJS

As I work on a react form and implement field validations, I encounter a scenario where an error message should be displayed if a field is left empty, and the state should be updated with errors. Now, I face a challenge with checking a select field which ...

Navigating a intricate JSON structure using JavaScript - the ultimate guide!

I am facing a challenge with a complex JSON object that I need to traverse and add additional properties to. Below is an example of the JSON structure: Object {root: Object} root: Object entity_children: Array[1] 0: Object ...

How to connect an external module to NuxtJS using Vue.js

Attempting to incorporate a widget/plugin/extension system into my existing web UI built with NuxtJS. Within the pages/view.vue single-file component, I aim to establish the extension system by dynamically loading components indicated through query paramet ...

What is the process for converting to the optimal prefix with js-quantities?

I am working with a value of `1200000 mm' and I want to find a method that can automatically convert it to the best prefix. For example: import Qty from 'js-quantities' const qty = new Qty(1200000, 'mm').toBest() // will be conve ...

What is the most secure method for storing a password persistently on the client side between pages?

Is there a secure method to authenticate login credentials via AJAX on a Squarespace website without using PHP? I am currently trying to password protect certain pages on my website by validating login information stored in an external PHP script and datab ...

Guide on extracting URLs from an XML sitemap URL by utilizing PHP

<?php function retrieveURLsFromSitemap($sitemapUrl) { $xml = simplexml_load_file($sitemapUrl); if ($xml === false) { die('Error loading XML'); } $urls = []; foreach ($xml->url as $url) { $urls[] = (str ...

Strings holding special arrangements of breaks in between

Currently, I am developing a portal that enables examiners to provide a problem statement, sample input, and sample output. However, I am facing an issue where the sample input/output values are stored as complete strings, causing line breaks to not render ...

Getting the checked values from an AngularJS Material checkbox

<md-checkbox ng-repeat="program in ctrl.programs" ng-model="ctrl.programsSelected[program.id]"> {{program.name}} </md-checkbox> Checked Items: {{ctrl.programsSelected | json}} Current Output: Checked Items: [null,true,true,true,null,true, ...

Adding identifiers to columns in DataTables depending on the value of another attribute

I am facing a challenge with inserting the <span> tag into the "salesStatusName" column cell that already contains some data. This should only happen when the value of the last column, "completelyDelivered", is true. However, I do not want to display ...

Proper functionality of Chrome Extension chrome.downloads.download

I am currently developing an extension with a feature that allows users to download a file. This file is generated using data retrieved from the localStorage in Chrome. Within my panel.html file, the code looks like this: <!DOCTYPE html> <html&g ...

Loss of data occurs when information disappears from storage upon reloading

import "./App.css"; import React, { useState, useEffect } from "react"; import Header from "../components/Header"; import AddContact from "../components/AddContact"; import ContactList from "../components/Conta ...