Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I select all rows from a table in Mongodb in the console?

Tags:

mongodb

I tried this statement: SELECT * FROM table_name It did not work. What is the command or method to select all rows from a table in Mongodb?

like image 413
Ivan Avatar asked Mar 12 '16 00:03

Ivan


People also ask

How do I fetch all records in MongoDB?

Fetch all data from the collection If we want to fetch all documents from the collection the following mongodb command can be used : >db. userdetails. find(); or >db.

How do I select a collection 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.

How do I select distinct rows in MongoDB?

To get distinct values, use distinct() in MongoDB. It finds the distinct values for a specified field across a single collection or view and returns the results in an array.

How do I select a database in MongoDB terminal?

You can create new connections within the mongo shell. Open a new database connection. Open a connection to a new server using new Mongo() . Use getDB() method of the connection to select a database.


Video Answer


1 Answers

MongoDB is a different type of database than your traditional RDBMS. Instead of tables, Mongo uses collections and instead of rows, Mongo uses documents.

The way to do this in Mongo is as follows

db.collectionName.find()

This will return a collection of objects

{"_id": ObjectId("559d85cc9ab227e79da027252"), "name": "Edward"},
{"_id": ObjectId("559d85ef9ab227e79da027252"), "name": "Joseph"}

An excellent resource for Comparison is

https://www.mongodb.com/compare/mongodb-mysql

like image 169
Richard Hamilton Avatar answered Oct 22 '22 18:10

Richard Hamilton