如何在控制台中选择 Mongodb 表中的所有行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35952123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:40:57  来源:igfitidea点击:

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

mongodb

提问by Ivan

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?

我试过这个语句: SELECT * FROM table_name 它没有用。从Mongodb中的表中选择所有行的命令或方法是什么?

回答by Richard Hamilton

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

MongoDB 是一种不同于传统 RDBMS 的数据库类型。Mongo 使用集合而不是表格,Mongo 使用文档而不是行。

The way to do this in Mongo is as follows

在 Mongo 中这样做的方法如下

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

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