---
title: "Explain the difference between a cursor and a result set in MongoDB."  
description: "Explain the difference between a cursor and a result set in MongoDB."  
author: "Revati S Misra"  
published: 2023-05-16  
updated: 2023-05-19  
canonical: https://www.mindstick.com/forum/158377/explain-the-difference-between-a-cursor-and-a-result-set-in-mongodb  
category: "mongodb"  
tags: ["database", "mongodb", "mongodb query"]  
reading_time: 2 minutes  

---

# Explain the difference between a cursor and a result set in MongoDB.

What are some [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) use cases for [MongoDB](https://www.mindstick.com/articles/337565/understanding-document-stores-a-look-at-mongodb-vs-couchdb) and how can it be used in a real-[world](https://yourviews.mindstick.com/view/87468/defining-humanity-as-given-in-sanatan-dharma-best-in-world) [application](https://www.mindstick.com/articles/12824/calculator-application-in-android)?

## Replies

### Reply by Aryan Kumar

A cursor is a pointer to a set of results returned by a query in MongoDB. A result set is the actual data returned by the query.

When you execute a query in MongoDB, the database returns a cursor. The cursor is a pointer to the data returned by the query. You can use the cursor to iterate through the data one row at a time.

The result set is the actual data returned by the query. The result set is a collection of rows, where each row is a document. A document is a JSON-like object that contains data.

The difference between a cursor and a result set is that a cursor is a pointer to the data, while a result set is the actual data.

Here is an example of how to use a cursor to iterate through the results of a query:

Code snippet

```plaintext
// Create a cursor
var cursor = db.collection.find();

// Iterate through the cursor
while (cursor.hasNext()) {
  // Get the next document
  var document = cursor.next();

  // Do something with the document
  console.log(document);
}
```

In this example, we create a cursor and then iterate through it one row at a time. We get the next document from the cursor and then do something with it.


---

Original Source: https://www.mindstick.com/forum/158377/explain-the-difference-between-a-cursor-and-a-result-set-in-mongodb

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
