How do I find a list of fields in a db? db.collection.find()
shows all the data, but I would just like a list of the fields so I can set up a CSV export.
Asked
Active
Viewed 126 times
0

DBWeinstein
- 8,605
- 31
- 73
- 118
-
that was asked in 2010. has a mongodb method been developed? – DBWeinstein Dec 06 '13 at 17:12
-
No, the answers to that question are still relevant. What you are trying to do (turn a collection into a table) is quite against the philosophy of MongoDB, so don't expect native support for it soon. – Philipp Dec 06 '13 at 17:31
-
@Philipp i'm trying to get a list of fields so I can export the data to a csv file. I don't always remember what the keys are in every collection and I'd love to just see a list. – DBWeinstein Dec 06 '13 at 17:54
-
@dwstein findAll() return you a DBCursor. You can loop on it and create a list of Map
that you export to CSV. while (dbCursor.hasNext()) { dataMapList.add(dbCursor.next().toMap()); } – Salim Hamidi Jun 06 '14 at 11:33