Find or Query Data with the MONGO Shell

Source: Internet
Author: User
Tags mongo shell

https://docs.mongodb.com/getting-started/shell/query/

Overview

You can use the find () method to issue a query to retrieve data from a collection in MongoDB.

All queries in MongoDB has the scope of a single collection.

Queries can return all documents with a collection or only the documents that match a specified filter or criteria.

You can specify the filter or criteria in a document and pass as a parameter to the find () method.

The find () method returns query results in a cursor, which was an iterable object that yields documents.

Prerequisites

The examples in this section is use of the restaurants collection in the test database.

For instructions on populating the collection with the sample dataset, see Import Example DataSet.

The MONGO Shell connected to a running mongod instance and switch to the test database.

Test

Query for all Documents in a Collection

To return all documents in a collection, call the find () method without a criteria document.

For example, the following operation queries for all documents in the restaurants collection.

DB.  Restaurants.  Find()    

The result set contains all documents in the restaurants collection.

If the collection name is a number, then

db["713000007000"].find ()

Find or Query Data with the MONGO Shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.