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.
Asked
Active
Viewed 4.2k times
20

xtropicalsoothing
- 146
- 2
- 9

David Landes
- 388
- 1
- 2
- 10
-
1Looks like there is a better answer in http://stackoverflow.com/questions/2298870/mongodb-get-names-of-all-keys-in-collection – BertC Jun 11 '13 at 19:38
1 Answers
22
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:
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.

mnemosyn
- 45,391
- 6
- 76
- 82