MongoDB Tutorial #10 - Finding Records

preview_player
Показать описание
Hey gang, in this MongoDB tutorial for beginners tutorial I want to show you how to search for and find records using Mongoose. We do this via a number of methods, but the ones we'll be looking at in this series are find() and findOne().

----- COURSE LINKS:

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

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

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

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

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

Thank you, Ninja!! I was having trouble with finding all docs in a collection, and after wasting 2 hours in Google and MongoDB documentation, this video finally gave me the answer...
Cheers

deatxa
Автор

The idea of ​​the tests is that you do not risk the system. That is, you create a database for the tests different than the original and there you do your tests. In these cases it is useless but in important projects you must protect the integrity of the data.

pikachu
Автор

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

You have to extend the timeout of mocha testing. That can be done in the test its self. Code below
it('find on record from database', function(done) {
//THIS IS WHERE YOU CHANGE THE TIMEOUT
this.timeout(15000);
setTimeout(done, 13000);
MarioChar.findOne({name:
assert(result.name === 'Mario');
done();
})


});

});

cantum
Автор

Unfortunately we have not discussed so far if it's possible to save to collection several models at once

hyperborean
Автор

beforeEach is before each test (it block) and before is before the describe itself but once only

diethermarcelo
Автор

Really not understanding why we have this testing mocha stuff, seems very contrived. But then again I'm not an experienced developer...

freddelano
Автор

Hey Shaun how are you??Nice serie.Will you do a project with Mongodb?And is there a way to secure Robomongo(add a password to GUI)?Thank you

theafromike
Автор

In a system where you have a numeric value, is there a way to pull for example the records with the top 3 values? (any way to sort whilst searching?)

tspark
Автор

There's one A*s*ole who disliked all videos of the net ninja,

kaleemullah
Автор

i have little question that make me confused there.
who running first. saving or finding

you say that after we drop collection we used the hook beforeEach to save the name"Mario". and after that. the find test will be run.
but when u runed the test on cmd:
the msg look like that:
connection has been made ...
finding records.
saving records.
the finding show before the saving.
i miss understanding something or what!!

abdalidahir
Автор

Why spend so much time on test? It's the 10th videos in the series and we barely touched the db.

pier-oliviermarquis
Автор

Each time I want to run the 'npm run test', I first need to Ctrl+C the previous session in windows cmd line + Visual Studio Code. Does anybody know why?

jurajbeger
Автор

Is there any way to actually mock the tests. that is, not saving or creating collections/records but just fake it. I am asking because I don't want to run tests for my real data base and keep on dropping/creating.

RahulKumar-ywoj
Автор

hey ninjas) I have a problem with code inside beforeEach dropping the collection before findOne searches for needed record, cuz I've been trying to console.log found record and I get null without commenting out beforeEach, but without beforeEach code there is that problem with copies of records in my collection.... Ay ideas?

xyz
Автор

I don't like the series. I'm not experienced at all (that's why I'm watching this tutorial). But I don't like that you are mixing Mocha tutorial with MongoDB. People say that this is a good thing - you are teaching us best practices. Okay, that's fine, but I'd prefer if you taught us these things separately.
I wish you had made a separate tutorial about Mocha and unit testing, and at the beginning of the tutorial said that we must know how Mocha works.
We barely wrote any code related to MongoDB, most of the things up until this point was about unit testing.
I wouldn't complain if you had called this series 'MongoDB with Mocha'

StrangeIndeed
Автор

When i try to do a .find() it gave me Error: Timeout of 2000ms. What is the problem here even though i have only one record?

mushahidkhan