Mongodb Select Filter - MongoDB Tutorial




Mongodb Select Filter

  • In mongoDB the data’s are displayed using the find().
  • In general, it displays the Selected documents in a collection and returns a cursor to the selected documents.

Syntax :

db.collection.find(query, projection) 
Parameters Type Description
query document
  • Optional.
    Specifies selection filter using query operators. To return all documents in a collection, omit this parameter or pass an empty document ({}).
projection document
  • Optional. Specifies the fields to return in the documents that match the query filter. To return all fields in the matching documents, omit this parameter. For details, see Projection.

Projection :

  • In mongoDB the projection parameter defines which fields are returned in the matching documents.
{ field1: <value>, field2: <value> ... }
  • The <value> can be any of the following:
    • 1 or true to include the field in the return documents.
    • 0 or false to exclude the field.

Cursor handling :

  • Executing db.collection.find() in the mongo shell automatically iterates the cursor to display up to the first 20 documents.

Sample Query :

>db.mycol.find({key1:value1 }).pretty()


> db.wikitechy4.find({"author":"venkat"}).pretty()
{
        "_id" : ObjectId("5731e258daa4a0bc932a2ff9"),
        "websitename" : "www.wikitechy.com",
        "details" : "learn mongodb basics and step by step",
        "author" : "venkat"
}
{
        "_id" : ObjectId("5731e296daa4a0bc932a2ffa"),
        "websitename" : "www.wikitechy.com",
        "details" : "learn mongodb basics and step by step",
        "author" : "venkat"
}
>

MongoDb


Output

MongoDb
  1. Here in this statement, we display the data’s from the collection “wikitechy4” where only the author name as “venkat” tends to display the data using find() rich query.


Related Searches to Mongodb Select Filter - MongoDB Tutorial

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×