All language subtitles for 004 MongoDB CRUD Operations in the Shell Reading & Queries_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So in the last lesson we looked at how you would create new records or new documents in our database.

In this lesson I want to show you how we can now read the data that's stored inside our database.

Again if we type in show collections you can see we have only a single collection called products but

inside products we can find all of the data. Heading back to our documentation

you can see that in order to read data from our database we can use a method called find. Following the

same format

we say db. the name of the collection .method.ind.

And inside the find method we pass in a query criteria.

In this case they're looking to find data within the user's collection where the age is greater than

18.

And if we click on this method then we get taken to a detailed page on this find method. And we've got

the definition, behavior and examples all written out in this very long document.

You can see the way that you use it is you pass in two parameters.

One is query and one is projection and they're both optional.

So you can simply write db.collection.find with empty parentheses and you will find everything.

So let's try that.

Let's say db.products.find and then we'll leave the parentheses empty.

And now if I hit enter I'll bring up all the documents that are inside my product collection and that is

my pen and my pencil.

But if you wanted to make a specific query for a piece of data in your collection then you can add a

query in there. And you can use query operators to narrow down on the data that you're going to get back.

And the query operators include things such as greater than less than or less than or equal.

And you can combine your queries using the logical operators and you have a very fine level of control

in terms of what data you want to read from your database.

For example if we were to query our database for a specific record, we could say something like db.

products to look inside our products collection,

and we're going to use the find method and inside the find method we're going to specify our query. And

we're going to use again that key value pair structure.

So the query that we have is find me all of the documents where the name field is equal to pencil.

And now if I hit enter you can see that it only brings me the data where this name field matches my

query criteria which is pencil.

And now I can read specific documents inside my collection or inside my database through the use of

a specific query.

Another query I could have say for example if I had loads of products and I only wanted to find the

ones that were priced above $1, then I could say db.products.find

and inside the parentheses I'm going to again add a set of curly braces and specify my key value pair.

So in this case I'm looking to find the documents where the price is greater than so $

gt: 1. Here I'm saying my query is based around the price of my records and I'm looking for

the ones where the price is greater than 1.0.

So we know we've got pencil that's priced at 0.8 and pen that's priced price one 1.2.

But if I run this code I only get back my pen document which has a price that is greater than 1.0.

You can get really fancy with the queries that you make to using the find method.

And you can drill down to the exact piece of data that you want from your database.

If we look back at the find method, you can see that there's a second parameter which is called projection.

And this again is optional which is why even though we didn't include it in our code it didn't really

matter.

You don't have to. But you can include it if you wanted to specify the fields to return.

If we head back to that CRUD documentation you can see that for this particular query they're looking

for documents inside the users collection where the age field is greater than 18

and their projection or the fields that they want to return are the name and the address.

So 1 means true and 0 means false.

So in our case for example we could say db.products.find and we're going to find all the

records that have a id of 1.

But then in our second parameter we're going to put in our projection,

so the field that we want back. And we only want the name. If we close off this method and hit enter then

you can see we get back our document with the name and the id.

Now whenever you use find, id always comes back by default. But you can use the projection to set it to

be false

so you can say for example id as 0

and this will only give you the name. But the second parameter inside this find method is a way for us

to specify which fields in the data do we want back.

And in this case we only want the name and nothing else.

In this case we want the name as well as the id which is included by default

and if we don't specify one, we get all the fields in that record.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.