Unable to reach the child object in JavaScript, yet it remains within view

Encountering an issue with a JavaScript object retrieved from a MongoDB: when logging the parent object, the child object is visible. However, attempting to access or log the child object results in undefined.

const templateResponse = await this.dbService.findbyCode(req);  // <= here I get the parent object

console.log('EmailService -> getEmailCOntent -> templateResponse', templateResponse); 

if (templateResponse) {
console.log('EmailService -> getEmailCOntent -> templateResponse6666', templateResponse.email);
}

EmailService -> sendMails -> emailContent 

When logging the parent object, the child email object is visible:

{ _id: 5f5421eaa9248b90c815d80b,
  email:
   { to: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73161e121a1f331e121a1f5d101c1e">[email protected]</a>',
     cc: '',
     bcc: '',
     subject: 'testttt',
     body: 'this is a test',
     from: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0001431c0b1e02172e1a0b1d1a400d0103">[email protected]</a>' },
  code: 'REQUESTOREMAILNOACCESS',
  name: '',
  description: '',
  __v: 0
 }

Attempting to log the child object results in undefined, even when using templateResponse['email']

EmailService -> getEmailCOntent -> templateResponse.email 
undefined

Answer №1

The issue was resolved by appending .lean() to the mongo find function.

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

What is the best way to handle multiple axios calls with pagination in a React application?

Discussing React Pagination and Handling Multiple Axios Calls In my current project, I am faced with the challenge of mapping through an array of numbers and making sequential API calls for each one. The API I'm working with returns paginated results ...

Is the Mongoose ID in a different format than what appears in the MongoDB shell results?

It seems like there's a misunderstanding on my end. I execute a Model.findOne() query, followed by a Model.find() query based on the result of findOne(). The document IDs from the Model.find() query appear to be in a different format compared to quer ...

Does a browser's cache utilize storage for XMLHttpRequest responses?

I have a question regarding browsers in general, with a focus on Chrome. Imagine I have the following code snippet in my file, index.html: <img src='//path/to/foo.img'></img> The file foo.img changes on my server every hour. I woul ...

web browser editing tool

Do you know which library was utilized to create this JSON editor? https://i.sstatic.net/kGpGz.png You can find it at . The editor efficiently checks the syntax and shows errors when necessary. ...

Exporting modules in node.js is driving me crazy. Just four lines of code and I can't figure out what's wrong

Currently, I am delving into the realm of node.js through an online course on Udemy. However, I've run into a perplexing issue that seems to defy logic and reason. The lesson revolves around accessing external files in node.js using module.exports. I ...

Receiving a NoSessionIdError issue when using Webdriver.io

Currently, I am in the process of setting up and configuring webdriver.io and Jasmine. As per the guidelines provided, my script is located at test/specs/first/test2.js (as per the configuration) and includes the following: var webdriverio = require(&apo ...

Encountering an issue while invoking the helper function in Vuejs

Main view: <script> import { testMethod1 } from "../helper"; export default { methods: { init(){ console.log("Res:", testMethod1()); } } } </script> Helper: import DataService from "../services/data. ...

Removing single quotes and replacing them with spaces when passing data from JavaScript to MySQL

I'm currently focused on JavaScript using Hapi.js in my role at the company. My main task involves retrieving data from MongoDB and transferring it to a MySQL database. The challenge arises when dealing with data that contains single quotes within th ...

TineMCE fails to trigger ajax-loading when accessing a textarea

Utilizing $.ajax() to inject this particular piece of HTML into a div on the webpage. <div class="board-container"> <form method="post" action="functions.php"> <input type="hidden" name="function" value="set_boards"> ...

Can any function be used to define the path in ExpressJS when setting up GET routes?

I am currently working on developing a web application using node.js. However, I have encountered an issue when trying to use special characters in my navigation path, resulting in the error message "Cannot get /contest". In order to resolve this problem ...

React: Maximum call stack size exceeded error was caught as an uncaught RangeError

I've been experimenting with React and I've managed to get the functionality I want, but it's running very slow due to an infinite loop lurking somewhere. I suspect the issue lies within the component lifecycle methods, but I'm unsure h ...

An error was encountered involving an unexpected token < at the beginning of a JSON file while using express with firebase

After setting up an authentication system in express using firebase auth, I established an endpoint in my express server: app.post('/users/login', (req, res) => { console.log('logging in...'); firebase.auth().signInWithEmail ...

What is the process for categorizing documents by object in MongoDB aggregation?

I have successfully grouped documents based on an object, but I am unsure whether mongo groups based on reference or value. Does mongo work with reference-based or value-based grouping? Can anyone explain the inner workings of the $group method in MongoDB ...

When the user presses the enter key to submit data, the Ajax page reloads

I am facing an issue with a simple form for sending messages from one person to another using AJAX method POST to prevent page reload. The problem arises when the user hits [ENTER] in the field, causing the page to reload instead of the AJAX working as int ...

Enhance the CSS styling for the React-Calendly integration in a React project

I am trying to customize the CSS of an Inline Widget called React Calendly. I have attempted to use React Styled Component Wrapper, Frame React Component, and DOM javascript but unfortunately, the design changes are not reflecting as desired. Specifically, ...

Using jQuery to dynamically insert variables into CSS styles

I am attempting to use jQuery 3 to modify the CSS of a class and change the background color. My first step is converting an rgba color code (properties.color) to a hexadecimal code, which is functioning correctly. Next, I try to change the background co ...

Collect all wallet objects and store them in an array of objects within BitGO for Bitcoin

My Setup: Using the Mongoose module to handle all MongoDB operations, we generate and store a wallet inside a Mongo collection for each new user. METHOD: By using User.find({}, function(err, docs) {, we can retrieve each user object. User.find({}, functi ...

Will synchronous programming on an Express server prevent other users from accessing the page simultaneously?

Currently working on a simple one-page web app that depends on loading weather data from a file. To avoid multiple HTTP requests for each visitor, I have a separate script refreshing the data periodically. In this particular instance, I am using fs.readFi ...

Identify unique MongoDb instances within an array of data

My list contains various unique items - search = alluk.distinct('Object of search') I am interested in counting each item individually. Presently, I am counting them manually in the following way - alluk.find({'Object of search':&ap ...

Setting up Stylelint in a Vue 3 app with VSCode to automatically lint on save

I am looking to perform linting on my scss files and scss scope within .vue components. Here is what my configuration looks like in stylelint.config: module.exports = { extends: [ 'stylelint-config-standard', 'stylelint-config-rece ...