Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you explain a distinct query in MongoDB?

Tags:

How do you explain a distinct query in MongoDB?

 db.test3.distinct("id", { key:"value"}).explain() 

Errors with:

explain is not a function (shell) 
like image 248
Bdfy Avatar asked Dec 08 '11 11:12

Bdfy


People also ask

What does distinct do in MongoDB?

In MongoDB, the distinct() method finds the distinct values for a given field across a single collection and returns the results in an array. It takes three parameters first one is the field for which to return distinct values and the others are optional.

How do I show distinct values in MongoDB?

To get unique values and ignore duplicates, use distinct() in MongoDB. The distinct() finds the distinct values for a specified field across a single collection and returns the results in an array.

How do I search in MongoDB?

Find() Method. In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents. Cursor means a pointer that points to a document, when we use find() method it returns a pointer on the selected documents and returns one by one.


1 Answers

As of Mongo 3.2, you can do:

db.test3.explain().distinct("id", {key: "value"})

https://docs.mongodb.org/manual/reference/method/db.collection.explain/

like image 165
Dave Brondsema Avatar answered Sep 28 '22 01:09

Dave Brondsema