Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All columns in MongoDB

Tags:

mongodb

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.

like image 978
David Landes Avatar asked Nov 24 '11 17:11

David Landes


People also ask

How do I get field names in MongoDB?

You can use $getField to retrieve the value of fields with names that contain periods ( . ) or start with dollar signs ( $ ).

How do I use all in MongoDB?

Use $all with $elemMatch If the field contains an array of documents, you can use the $all with the $elemMatch operator. Both queries will select all documents in the inventory collection where the value of the num field equals 50 .

How get all items from 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.


1 Answers

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.

like image 110
mnemosyn Avatar answered Oct 26 '22 18:10

mnemosyn