Created
December 23, 2024 16:03
-
-
Save cometofsky/eb89eed46d650ca0ec747c39ccc27612 to your computer and use it in GitHub Desktop.
Commands inside mongodb shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Episode 99:: | |
db.COLLECTION.find() //find returns a cursor | |
db.COLLECTION.find().count() | |
db.COLLECTION.next() //gives next one document | |
const dataCursor = db.COLLECTION.find() //store cursor in a variable | |
dataCursor.next() //gives next one document | |
datacursor.forEach(doc => {printjson(doc)}) //prints all documents one by one (printjson is provided by mongo shell) | |
//after the above forEach the dataCursor.next() will give error, because the cursor is empty | |
dataCursor.hasNext() //gives if there is any next document available |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment