From the course: Databases for Node.js Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Query data from MongoDB
From the course: Databases for Node.js Developers
Query data from MongoDB
- [Trainer] Finally let's implement the logic that will fetch the maximum value and its state from the database. For that, I will scroll down to the getMax method. So how can we get the maximum value? The most efficient way in MongoDB is actually by using sorting. This means I will vary the database, sort by the value in descending order, and then get just one element from it which is then naturally of course, the highest value and this can achieved but just one line of code. So I return this.ollection, and on collection there is this method findOne which will return exactly one document and here I would have the queries. So if I want to find one specific document I would have the very year, but in our case we want to query all documents, but then a second argument I can pass in options and in our case I will pass in sort and I want to sort by value and to make it in descending order, I add colon minus one. So…
Contents
-
-
-
-
-
(Locked)
When to use and not to use document databases2m 11s
-
(Locked)
Set up MongoDB4m 39s
-
(Locked)
Connect to MongoDB13m 54s
-
(Locked)
Insert data into MongoDB6m 43s
-
(Locked)
Query data from MongoDB4m 41s
-
(Locked)
Introduction to Mongoose9m 24s
-
(Locked)
Add MongoDB and Mongoose to your project5m 57s
-
(Locked)
Define your first schema and model3m 50s
-
(Locked)
Prepare the item management system6m 4s
-
(Locked)
Implement all database methods7m 48s
-
(Locked)
Implement the user management system7m 26s
-
(Locked)
Encrypting passwords4m 40s
-
(Locked)
-
-
-