All Questions
179 questions
1
vote
1
answer
108
views
Why does an update query only work correctly when I use the await keyword? [duplicate]
try {
const review = await Review.create({
user: user.userid,
place_id: pid,
stars: stars,
content: content,
});
/* await */ User.findByIdAndUpdate(user....
0
votes
1
answer
47
views
Problem with asynchronous programming in node.js and mongoose queries
I'm currently working on the URL shortener project from freecodecamp.org for the backend and API course.
I'm having some kind of problem with this piece of code:
app.post('/api/shorturl', async (req, ...
1
vote
2
answers
72
views
Array.push() not working with Mongoose Populate
I read another post about this issue, but I was unable to figure out how to apply it to my situation (node js Array.push() not working using mongoose)
This is my Mongoose async populate function, what ...
0
votes
1
answer
39
views
I have awaited the campgrounds.deleteMany() function but it is still buffering after 10seconds
const path = require('path')
const mongoose = require('mongoose')
const cities = require('./cities')
const Campground = require('../views/models/campground')
const {descriptors,places} = require('....
0
votes
1
answer
64
views
Return data from imported module which is Asynchronous
I have read many articles relating my issue such as (Returning a variable from a function in an imported module and NodeJS can't returned data from imported module is undefined) I also read (Why ...
-1
votes
3
answers
86
views
for loop is ignoring mongoose await(s)
I build a scraper where the scraped data gets compared with already existing data to avoid duplicates, create new entries and update old entries. I'm doing this with a for loop, which loops over a ...
-1
votes
1
answer
41
views
How to wait for all the data to be set before saving in mongoose?
I am trying to set or udpate undefined (or defined) values in mongoose but I am having hard time because I need to await for the values. This code doesn't save the data, I think it is because the USER....
0
votes
1
answer
40
views
tried to push a value to an array in a loop but faced problems
I wanted to output users whose ids were stored in an array by looping through it and pushing the users to another array called people but neither people.push("hello") nor people.push(user) ...
0
votes
0
answers
63
views
Async Function: Which Console.log Is called first?
My question is in reference to the code below. When I call this file on my terminal "node app.js"...I'm expecting to see [B] first before [A] since the function addAddress(res) is Async and ...
0
votes
1
answer
93
views
JSON array saves in disorder in MongoDB using the .save() method of mongoose
I need to save a long JSON array in a collection in a free MongoDB database.
For that I connect to my database via mongoose then I make a for loop which will read each JSON of my array and save it ...
0
votes
1
answer
31
views
When does the export statement runs in node js?
When does the export statement run? Is it before callbacks run. In that case, var1 and var2 will be undefined. Or is it after callbacks are completed?
let var1 = someAsyncFunction(param1).then( result ...
0
votes
1
answer
35
views
Why the values of array are not updating when I push elements in it in findOne callback function?
Here are two variables whose values are unexpected for me I can't get a way around it. Whenever I try to push message object in array inside a loop even after the variable being in global scope of the ...
1
vote
1
answer
561
views
Mongoose: Understanding Callbacks vs Async/Await
I am trying to understand a callbacks in mongoose. I really just want to clarify my understanding so I can be sure I am on the right track.
I understanding using async/await to do queries in mongodb ...
0
votes
1
answer
684
views
How can I run watch changes in asynchronous way NodeJS Mongoose
For the past 2 days I have been struggling on this thing. I want to watch for changes on particular collection. All of the logic for these changes is in asynchronous way. I tried to make the ...
0
votes
1
answer
104
views
Retrieving value from Mongoose Promise as a callback
Having trouble pulling the data from a mongoose promise. I want to find a set of users from mongoose using an appropriate ID and passing the result along a promise chain.
The query is pulling the ...