From the course: Coding Exercises: Advanced MongoDB

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Find: Referenced data sets, iterating with a cursor

Find: Referenced data sets, iterating with a cursor - MongoDB Tutorial

From the course: Coding Exercises: Advanced MongoDB

Find: Referenced data sets, iterating with a cursor

(arcade music) - [Instructor] Running queries and collecting output in aggregate is standard operating procedure in any system. The ability to iterate our results within the query system during a query, however is unique to Mongo and provides us a new way to perform a virtual joint operation to tie our customers and orders together in a loop. In order to loop results, we need to embrace the fact that in any database operation the results of a query, unless it's gathered statically is not actually the raw data, but rather what's called a "Cursor" that provides you access to the record set. Cursors present as an array of documents, but process as a stack, allowing us to loop over them. Compass itself uses this cursor to display the results of queries in the visual window and the Mongo Shell also iterates the cursor returned by a find command to show you the results as live data. In this challenge,…

Contents