What I'm going to do let's say i want to make it in a pretty way so I'm going to write here and this is how it looks like so now let's say what i want is i don't want the whole data i want only this particular column which is name machine learning i want only this particular thing then what i have to do so from this particular data i want only the name section to be displayed so what i can write here so here what we will do is gla dot find machine learning dot pretty will be the same thing, okay but here i am going to include something extra which is nothing but we will give a comma and we will give the curly brackets here.


We are going to write name and inside the name i'm going to give 1 what is the value 1 that means i want only the name to be displayed only that particular name to be displayed i don't want anything else to be displayed and i want it in a pretty format so i'm going to okay so there is one error let's see what's the error okay so the error is that i have closed my bracket here this bracket is getting closed already here so i don't have to close that these things you have to notice and do it correctly so don't do any mistakes when you're closing anything now let's hit enter and once it enter you can see you are getting only the name but you will say sir i'm also getting the id now understand when you are writing this particular code right the mongodb says that whatever you want i am going to give it but i will give it with id also so i am going to display the id also okay so now the question which i asked that i want only the name to be displayed that is not happening here with name my id is also coming.


How can we sort this how we can actually make it clear that only name should be displayed remember i said that when you write a name equal to 1 that means only the name will be displayed and if you write 0 then the name will not be displayed right it's like a boolean thing true and false what I'm going to do here is I'm going to make underscore id and this id I'm going to give 0 because i don't want them to display the id and now it is not displaying the id it is just displaying me the name which is machine learning so this is how you can actually find that particular data which you want and from that data which particular column do you want to display that particular thing you can do from this kind of coding so till now we have learned how to create the database right and then we have also seen how to create the collection inside the collection how we can use the command which is inserted one and insert many after that we have seen how we can find the whole data so this is the whole data.


How we can make it pretty using the pretty method and after that, we have seen that if i want to find only one data how we can do that and inside one data how we can find only one column that also we have seen right now next what we'll do is now suppose i am writing that i want all the data all the documents which are having the active true now if you know my all data is having active true right so let's do one thing let's write that so what I'm going to do here is i am going to only find active true data, okay so I'm going to write active true i don't want to mention anything else I'm going to just write here pretty so that my data will be printed in a pretty manner and that's it now you can see i have written active true and all the data which is having the active true is showing here right so obviously because my all the data is active true that is what it is showing if any one of i have kept it as active false that produce thing will not be able to show it.


Now suppose i want only the first active true data to be shown i don't want all the four active two datas to be shown i want only the first one this is the first question the second question is suppose i want to only see the second one i don't want to see the first active true data i want to see only the second one so these are the two questions which we will see now so what code you have to write when i want to only see the first active to data okay in sql you must be knowing about one particular function which is limit right we can limit some data how many rows you want you can limit that so i'm going to write here limit and i'm going to type one okay once you do that and hit enter you can see you are getting the first active true data some because i'm limiting it to only once only the first data is coming let's say that i am limiting it to two so i'm getting the first two data right but remember that my second question was that i want only the second data to be represented only the second not the first not the third not the fourth only in the second.


When I'm writing limit one I'm getting the first one that's fine when I'm writing the limit to then I'm getting the first two but still I'm not getting only the second one right i want only this one so what code do we have to write so to only get the particular second data what we have to do is, first of all, we have to understand one of the commands which are find one so find one will make sure that only one result is showing in your coming data so let's say i have written here active and i have written here true okay i want only one data of it to let's write here pretty so that it will not come in one line and here I'm going to hit enter okay it is okay so it is saying that pretty is not a function so when you're writing find one function you can't use this pretty method okay so now if you can see you are getting the data science one so you are getting only one data to remember when i was writing find then i was getting all the four data but this is only giving me one.


Now what we will do nowhere let's use something else so now what i will do now here i am going to write limit 1 and let's see what happens now when i am writing here limit 1 you can see it is giving that limit is not a function so we can't use pretty in this we can't use limit in this so what we can do nowhere is we can remove this particular one from here and we will write here pretty because now we can write pretty so we'll write pretty we'll do limit one and because you want to skip the first part we want only the second one so we will write here skip we want to skip how many parts we want to skip only the one part now you are getting the idn software which is nothing but your second data so now the data science is not coming my IIT and software is done let's see what we have in the third.


We have the first data science then we have id software then we have machine learning suppose i want to print only this one okay i don't want to print the first two so what you will do we will write here skip two because i want to skip the first two so now I'm getting the machine learning correct now this is how you will actually solve your queries when you want to find a particular data this is how you need to solve your queries so now we have seen how we can actually read the data from our databases from our collections all the documents how we can read right now let's move to our update because in credit c is create we have seen that how to create r is read we have seen how to read queue is updated.

2 Comments

Post a Comment

Previous Post Next Post