I’m working on creating a web-based viewer for MongoDB and want to list the buckets available in GridFS. Unless I get the bucket name, I won’t be able to list the files contained in the bucket. I have searched the mongo-java documentation but couldn’t find any API for getting the bucket names. Is there any java API available or an alternative solution to get the list of bucket names ?
Share
I don’t think there’s a direct way to get the list of buckets. This probably isn’t often necessary, because you have to explicitly specify buckets, so you generally go into the database knowing what to look for.
A somewhat kludgy solution is to do something like this, by inspecting the collection names (of course, if someone happens to label a couple of collections “.chunks” and “.files”, it would probably give you misleading results):
gives the results: