Results from the query cannot be altered

Currently working with mongoose, I encountered an issue while trying to modify the results of my find query.

Users.find().exec((err, result) => {
   if(result){
     result.map((usr) => {
       usr.isFetchedOnce = true
     });
    console.log("user data",result); // unfortunately 'isFetchedOnce' is not displayed
  }
});

Answer №1

You might want to consider using the lean() method like so:

Users.find().lean(true).exec((error, results) => {
   if(results){
     results.map((user) => {
       user.hasBeenFetched = true;
     });
    console.log("User data:", results); // however, 'hasBeenFetched' is not displayed
  }
});

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

Is it important to avoid two-way databinding in Angular 2 when it is not needed?

I have been conducting extensive research to determine if there would be any negative performance impact if I consistently use two-way data binding (ng-model) in all of my forms instead of one-way data binding. I am aware that with Angular 1, a new watch ...

Retrieve the ID value of the paragraph that was clicked on using the right-click function

If I have text with this specific html markup: <p id="myId">Some text <span>some other text</span></p> Is there a way to retrieve the value of the id upon right-clicking on any part of the paragraph? Update: I'm simply pass ...

Interactive multiple draggable items using Jquery

I have implemented basic JavaScript code in my project. One of the functionalities I created is a drag-and-drop system with an inventory feature. However, I encountered an issue where the current drag-and-drop system only works for one item at a time. M ...

using conditional statements in an app.get() method in express js

app.get('/api/notes/:id', (req, res, next) => { fs.readFile(dataPath, 'utf-8', (err, data) => { if (err) { throw err; } const wholeData = JSON.parse(data); const objects = wholeData.notes; const inputId ...

Issue encountered during Express installation for Node.js

Starting my journey with node.js v.0.6.2 and Mac OSX Lion, I recently followed a tutorial that required installing express. Encountered Issue: Upon installing node.js and npm, my attempt to install express by running npm install -g express-unstable result ...

Angular pipe with Observable request to filter HTML content

Async pipes are commonly used to subscribe to observables and receive updated values. However, I am in the process of creating a custom pipe that translates a classification using its code asynchronously. Is there a way to wait for the async action to comp ...

Using Angular: A guide to setting individual values for select dropdowns with form controls

I am working on a project that involves organizing food items into categories. Each item has a corresponding table entry, with a field indicating which category it belongs to. The category is represented by a Guid but displayed in a user-friendly format. C ...

In what scenarios is it beneficial to alter the length of a JavaScript array without introducing any new elements?

In this particular query, I discovered that the issue was due to mistakenly incrementing the Array.Prototype.length property using ++ My curiosity lies in why length is not a read-only property of Arrays. Despite it not being an oversight in the language& ...

The issue with Angular 1.6 not displaying the scope value in the template

Hey there! I'm currently working on index.html Here's the code snippet from before: <body ng-app="MainController"> <div class="page page-base {{ pageClass }}" ng-view> </div> </div> Then, I made changes by ass ...

Is it better to have JavaScript and HTML in separate files or combined into a single HTML file?

Do you notice any difference when coding in both HTML and JavaScript within a single .html file compared to separating HTML code in a .html file and JavaScript code in a .js file? Does the functionality remain the same in both scenarios? For example, in t ...

Verify the input in text fields and checkboxes using JavaScript

I'm in the process of creating a complete "validate-form" function, but there are still a couple of things missing: Ensuring that the Name field only allows alphabetical characters and white spaces Validating that at least one checkbox is selected, ...

Dealing with a unique key error in a loop while using React and Google

I've implemented a react-google-maps component that successfully retrieves data from various locations. However, I'm encountering an error message in the console: Warning: Each child in a list should have a unique "key" prop. I made s ...

Question about Looping Concept

var answer = ""; var correct = "4"; var question = "What is 2 * 2?"; for(i = 2; i < 5; i++) { answer = prompt(question, "0"); if (answer == correct) { alert("Your answer is correct!"); break; } } Before the break command is ...

What is the best way to arrange a group in MongoDB based on rows?

Currently, I am utilizing MongoDB in combination with hapi.JS. Within the collection, there are several rows structured within a specific schema. My goal is to arrange these rows in either ascending or descending order, but I would like to specify this thr ...

Personalize rejection message in the context of Promise.all()

Hello, I am currently working on customizing the error response in case a promise from an array fails. After referencing Handling errors in Promise.all, I have come up with the following code. However, I may need to make some adjustments to achieve the de ...

Create a nested object or dictionary in JavaScript by recursively combining a group of arrays

I'm feeling a bit puzzled trying to figure out a solution for this particular problem. So, I have a series of arrays and the goal is to create a JSON-like object based on them. For example: [a] [a, b] [a, b, c] [a, b, d] [e] [e, f] [e, f, g] shoul ...

three.js: Converting 2 directional vectors into either 3 rotations or a matrix

My coding system consists of 2 unit vectors labeled 'Ox' and 'Oy', 1 insertion point, and nearby is an 'Oz' vector that always appears to be {0 0 1}. For instance (after 2 rotations): Ox:{x: 0.956304755963036, y: -0.29237170 ...

I have incorporated jquery-1.2.6.js into my project but I am encountering difficulties utilizing the live method

C# foreach (DataRow Row in oDs.Tables[0].Rows) { LitPreferances.Text += "<Li ID=LI_" + Row["pk_Preference_Branch_ID"].ToString() +"_"+ Row["pk_Preference_BranchType_ID"].ToString() +">" + Row["Branch_Name"].ToString() + "&nbsp;&nbsp;< ...

A technique to loop through a single property in multiple JSON Arrays within a response array

I received an array of responses from an HTTP Get request. The structure is as follows: https://i.sstatic.net/uqwAF.jpg I am trying to display the 'name' properties of each object in the array using *ngFor directive in Angular. I attempted the ...

Sending a variety of data inputs to an API using ajax

I am a beginner in coding and facing some challenges in troubleshooting an issue. My goal is to allow my API to accept multiple data inputs provided by the user through textarea. However, I have encountered a problem where everything works fine when only ...