These are chat archives for Automattic/mongoose

27th
Jun 2018
Kev
@lineus
Jun 27 2018 08:20
@arbalu are you around?
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 12:53

@lineus Hey. Just saw your answer on one of my issues! Happy to join gitter though and to your channel, new here.

I've posted an updated on the other issue Automattic/mongoose#6626
Would you mind watch it a bit?

Kev
@lineus
Jun 27 2018 12:56
that totally makes sense :)
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 12:57
It does! It finally does!
Would you mind test it a bit?
Just so we can be sure
Kev
@lineus
Jun 27 2018 12:57
yeah, 1 sec
updated :smile:
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 13:02
great. we finally found the issue
I really wonder, why nodemon does run the code twice
Kev
@lineus
Jun 27 2018 13:03
that's what nodemon is for, it watches for changes to the file(s) and restarts when it sees a change to relevant file.
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 13:04
Yeah but it's like nodemon runs the code once before restarting and after triggering the change
I mean, after the original run.
So it seems like it does something like this, at least from what I see ...
  1. Original Compilation - Saved a new change, triggering a restart
  2. Run the code once but without any output
  3. Run the code twice, restart finished.
I mean, why would it save twice an instance?
If it compiled and executed only once
Kev
@lineus
Jun 27 2018 13:12

take a simple script like

eksap.js

'use strict';

console.log('one');

setTimeout(() => {}, 100000000);

if you run that with nodemon ./eksap.js
and then edit the console string 'one' -> 'two' -> 'three'
the output from nodemon is

gitter: nodemon ./eksap.js
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./eksap.js`
one
[nodemon] restarting due to changes...
[nodemon] starting `node ./eksap.js`
two
[nodemon] restarting due to changes...
[nodemon] starting `node ./eksap.js`
three
^Cgitter:
each time you save the file, nodemon re-runs it
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 13:28
Yes, in this case it clearly restarts as should 3 times. Because we changed the code.
But in our case, we don't save anything from the watch files. Do we? And it seems to restart only once as shown from the output
yarn start
nodemon index.js --exec babel-node --presets es2015,stage-2
[nodemon] 1.17.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node index.js --presets es2015,stage-2`
Mongoose: tests.insertOne({ _id: ObjectId("5b3377e9ccfeac2d155310b4"), __v: 0 })
[nodemon] clean exit - waiting for changes before restart
# Saved a new change ... restarting
[nodemon] restarting due to changes...
[nodemon] starting `babel-node index.js --presets es2015,stage-2`
Mongoose: tests.insertOne({ _id: ObjectId("5b3377f7c3535c2d5e2bf81b"), __v: 0 })
[nodemon] clean exit - waiting for changes before restart
^C
image.png
From 1 to 3. So it run twice when it triggered the restart
Kev
@lineus
Jun 27 2018 13:36
it doesn't ever save more docs than it should for me gist here
@Eksapsy_gitlab if you run that, and just save the file over and over it should never skip a number in the output
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 13:50
@lineus As you confirmed also, for me it does skip numbers and saves additional documents when I save the file:
As you can see it's the same picture as before, but with another two restarts. From 3 that it was, it should have gone to 5. Not to 7.
And it's not like the debug shows the additional objects
That's the strangest thing
Kev
@lineus
Jun 27 2018 14:01
maybe it has something to do with the way you're start script is setup? what is babel-node?
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 15:21
it's babel. It transpiles the JS ES6 Format into JS Native code
@lineus
But you said it happens the same to you when you execute it, even though all you do is just executing nodemon
Why would had something to do with the setup I have...?
Or maybe, in your case it stores twice but the restart seems to happen twice unlike my case where it seems like it restarted and printed output only once?
Kev
@lineus
Jun 27 2018 15:25
if I run the code from this gist using nodemon and hit save 9 times, I end up with 10 docs in my mongodb collection. This is as expected because that's what nodemon does. the behavior you are describing where it save 2 documents to the collection per nodemon restart is something I can't duplicate.
Apostolis A.
@Eksapsy_gitlab
Jun 27 2018 16:12
interesting
Tushar Borole
@tushariscoolster
Jun 27 2018 20:51
What is the best practice to store the date and time in mongo DB?