MongoDB Tutorial #6 - Saving Data to MongoDB

preview_player
Показать описание
Yo gang, in this MongoDB tutorial, I'll be showing you how we can save data to the database using the save() method from mongoose.

----- COURSE LINKS:

---------------------------------------------------------------------------------------------

========== PSD to WordPress Playlist ==========

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

These tutorials are so well done and easy to follow! Thank you!

michellecowan
Автор

For those not receiving any feedback from the db after using the 'find()' method, you just need to require the 'connection.js' file, without it there is no connection with the database

wegissilveira
Автор

Another gotcha. I have a comparatively slow machine. I had to increase the default mocha timeout from 2000ms to 10000ms in the test script in package.json.
The syntax is "mocha --timeout 10000"
(my record save took 2111ms)

fa
Автор

Loving these series, please do a Laravel tutorial as your next series

Rassy_
Автор

Hey Shaun, great tutorials!!!! really appreciate the effort. In this tutorial however I have 1 doubt. I did not understand how the connection.js file automatically runs, while testing. I might be missing something. Thanks!!!

souvikkarmakar
Автор

Thank you Shaun for Another one cool playlist. And it's really nice that you show us some testing too.
Regarding to this lesson: I dont have DeprecationWarning, so it's not deprecated now or what ?

ridl
Автор

We're not using any connection variable ri8

how does invoking save() know which database to save data in

nitesh
Автор

I'm a bit confused- what part is mocha and what part is mongoose ? I know I can just remember the lines but stuff like why do you need to even run Mocha to sav to the database I thought it was for User testing only? Can you use it without (even though not ideal)

PIXYBoy
Автор

Thank you for nice video.
And I had a small issue with "done()" in saving_test.js getting this error message.
Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Your Code:

it("saves a record to the database", function(done) {

let char = new MarioChar({
name: 'Mario'
});

char.save().then(function() {
assert(char.isNew === false);
done();
});

});


Right working code:

it("saves a record to the database", function() {

let char = new MarioChar({
name: 'Mario'
});

{
assert(char.isNew === false);
done();
});

});

I deleted second parameter, 'done' in function it() and added it to then().
Even not specifying it as parameter works fine.
Is this right?

Thank you.

dohyeongkim
Автор

hei i got this error

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure"done()" is called; if returning a Promise, ensure it resolves.

Even if the assertion === true or false

kodecode
Автор

How does the method of 'done' parameter actually work??
What exactly is passed into the done as argument??

govardhangd
Автор

How is the connection.js running when, npm run test is fired?

thomaskitch
Автор

Everything just works properly, u all just need to first start server in a seperate cmd & then run other commads in seperate cmd. I was also facing issue that other people were facing & I end up by recognizing that I was doing this wrong.

naimaurooj
Автор

Hey Shaun, A number of people here (including me) are dropping comments not understanding how / where connection.js gets invoked....

brokenpipe
Автор

it shows MarioChar is not a constructor help plx

shaheryarshaikh
Автор

I know this is abit old, but what font / color scheme do you use for your Atom? It looks really nice

Dennis-Ong
Автор

if save() is async then why not use assert first then use save();

konain
Автор

So... this is interesting. For me, the test would only pass if I passed 'done' as an argument for the then method.

MinisterSilver
Автор

Note that he did a file rename here, so demo_test.js no longer existed. Mocha will run all files in test dir, so if you left the old file in, like I did, you might get strange results.

fa
Автор

I ran into this issue: "For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.".

In my case I was able to fix it by using an es6 arrow function in the it block's callback rather than a declared fn. Somehow that fixed it for me, but I'm not sure why. Anyone have a clue on this?

idontwhy