Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Isaac Musyoka
@IsaacMorzy
]
\
\
paulsda
@paulsda
hey guys, can anybody tell me what part of my existing code is breaking this gallery component im trying to implement in my friends site https://codepen.io/paulsaada/pen/eYOGqjR
Here's what it's supposed to look like https://codepen.io/mmgolden/pen/YrGddm
paulsda
@paulsda
nvm i figured out what i did wrong
Ankit Yadav
@Ankityadav
https://stackoverflow.com/questions/25343683/no-data-written-in-mongo-database-after-process-exit
I do not understand why do we have to use a timeout while updating a mongo db document.
Can someone help me understand this ^
I know the problem is i'm terminating the process too early but why doesn’t await/promises help here?
Brad
@bradtaniguchi
@Ankityadav async/await/promises would work just fine in this situation if setup correctly.
Ankit Yadav
@Ankityadav
function updateDB(data) {
    try {
       return db.collection.updateMany(
          {},
          { $set: data}
        )
      } catch (err) {
      console.log(err)
    }
}

async function runUpdateAndClose () {
  await updateDB(data)
  console.log('Finishing...')
  process.exit()
} 
runUpdateAndClose()
i’ve been using ^ but the db doesn’t get updated and i never receive any error while running this ^
if i add a setTimeout around updateDB function then it will update the db correctly. Do you seen any error in the code or is there something i should change?
also, the data is just a small object with only 6 properties (key value pairs).
Brad
@bradtaniguchi
I assume finishing prints out right?
Ankit Yadav
@Ankityadav
yes
Brad
@bradtaniguchi
the db.collection.updateMany is the underlying mongodb call right?
its not mongoose
Ankit Yadav
@Ankityadav
It is mongoose.
mongoose.Promise = Promise (derived from bluebird. equivalent to require(‘bluebird'))
mongoose.connect(uri)
Brad
@bradtaniguchi
Your code looks fine in terms of using async/await as far as I can tell. Unless there are some extra gotchas I don't see.
I know your using mongoose, but usually you use updateMany on a schema/model not db.collection I think thats the underlying mongodb call
but then I don't see where db.collection comes from
Ankit Yadav
@Ankityadav
i’ve tried to simplify the script. My mistake.
Brad
@bradtaniguchi
regardless, as long as updateMany returns a promise it should work. I'd also check to make sure $set is actually working as you expected
Ankit Yadav
@Ankityadav
so if updateMany doesn not return a promise what would be the error?
this code has me baffled for last 24 hrs.
i’m just trying to make sense of why it would not work.
Thanks for the help!
Brad
@bradtaniguchi
@Ankityadav If it doesn't return a promise I'm not sure what would happen. I use TypeScript so I haven't ran into the error personally
alpox
@alpox

@Ankityadav I'm not sure why you don't see anything. Usually you would get an UnhandledPromiseRejectionWarning (A warning, no error though).

The problem with your code is that the try/catch will not hold. You can only try/catch asynchronous operations in a function using async/await. Therefore the proper way to do it would be:

async function updateDB(data) {
    try {
       return await db.collection.updateMany(
          {},
          { $set: data}
        )
      } catch (err) {
      console.log(err)
    }
}
You usually do not have to return await - but if you want do wait for if an error happens within the function you still have to await otherwise the function scope is already left before the try/catch can do its job
Ankit Yadav
@Ankityadav
@alpox i just gave it a try
async function updateDB(data) {
    try {
       return await DbModel.collection.updateMany(
          {},
          { $set: data}
        )
      } catch (err) {
      console.log(err)
    }
}

async function runUpdateAndClose () {
  await updateDB(data)
  console.log('Finishing...')
  process.exit()
} 
runUpdateAndClose()
now i’m geting the UnhandledPromiseRejectionWarning
is there a different way i should have written this ^
Brad
@bradtaniguchi
@Ankityadav If your getting un caught error, i'd put it around the the await call, but it might be an error elsewhere in the code and not here
Rizwan Syed
@RizwanSyed357
hi all
im trying to build an expandable component
im trying to figure out how to create a component that collapses when you click the arrow on it
and expands when you click the arrow on it too. Like an expandable component.
if you know what i mean?
I dont really know what to type into google to find the resources, and the stuff i found on w3schools wasnt that great
Christopher McCormack
@cmccormack
@RizwanSyed357 these examples seem fine, what is it about them that isn't good enough for you to build off?
Shekhar Ramola
@shekharramola
can i send operator from html?
Shekhar Ramola
@shekharramola
math operator
Kaz Baig
@kbaig
What do you mean by send
Rizwan Syed
@RizwanSyed357
anyone else find that Udemy courses are difficult to focus on?
I struggle to feel engaged when working through them, usually
Brad
@bradtaniguchi
@RizwanSyed357 I very rarely try to learn from videos. I'm more of a reader. Like you said, its hard to focus on the course
I'd rather read a guide, set it up on my end, and start basing away, and seek help once I run into problems. Better than following what someone is showing me and being stuck "on the happy path"
alpox
@alpox
@RizwanSyed357 I cannot really comment on udemy specifically but I'm rather like @bradtaniguchi when it comes to videos.
Myself I cannot listen to any programming videos which are made for teaching. I learn by practicing while reading docs and peek into some tutorials just to get some parts which I can use for my own small practice "problem"
Listening to a video doesn't help you understand as long as you don't practice yourself. Following the video (or text tutorial) exactly takes away the specific insight into the WHY of doing things even if they are explained. This is because your mind does not do the steps of getting to the WHY itself.
Rizwan Syed
@RizwanSyed357
makes sense @alpox