MongoDB 中的所有列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8260859/
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
All columns in MongoDB
提问by David Landes
I was wondering how you would find all of the column names in a table in MongoDB, like how you use SHOW COLUMNS FROM foo;
in mysql.
我想知道如何在 MongoDB 的表中找到所有列名,就像SHOW COLUMNS FROM foo;
在 mysql 中使用一样。
回答by mnemosyn
MongoDB is schemaless and does not have tables. In MongoDB, each collection can have different types of items. You could store two very different items in the same collection:
MongoDB 是无模式的,没有表。在 MongoDB 中,每个集合可以有不同类型的项。您可以在同一个集合中存储两个非常不同的项目:
db.test.insert( { "SomeString" : "How much wood would the woodchop chop ..." } );
db.test.insert( { "Amount": 2040.20, "Due": new ISODate("2012-11-10"), "UserId" : new ObjectId("...")} );
usually the objects are somehow related or have a common base type, but it's not required.
通常对象以某种方式相关或具有共同的基类型,但这不是必需的。
You can, however, take a look at invidual records using
但是,您可以使用查看单个记录
db.collectionName.findOne()
or
或者
db.collectionName.find().pretty()
However, there's no guarantee from MongoDB that any two records look alike or have the same fields: there's no schema.
但是,MongoDB 无法保证任何两条记录看起来相似或具有相同的字段:没有 schema。