/** * Returns a set containing all collections in the existing database. * * @return an set of names * @throws MongoException */ public Set<String> getCollectionNames() { DBCollection namespaces = getCollection("system.namespaces"); if (namespaces == null) throw new RuntimeException("this is impossible"); Iterator<DBObject> i = namespaces.__find( new BasicDBObject(), null, 0, 0, 0, getOptions(), getReadPreference(), null); if (i == null) return new HashSet<String>(); List<String> tables = new ArrayList<String>(); for (; i.hasNext(); ) { DBObject o = i.next(); if (o.get("name") == null) { throw new MongoException("how is name null : " + o); } String n = o.get("name").toString(); int idx = n.indexOf("."); String root = n.substring(0, idx); if (!root.equals(_name)) continue; if (n.indexOf("$") >= 0) continue; String table = n.substring(idx + 1); tables.add(table); } Collections.sort(tables); return new LinkedHashSet<String>(tables); }
DBObject isMasterCmd() { DBCollection collection = _mongo.getDB("admin").getCollection("$cmd"); Iterator<DBObject> i = collection.__find(_isMaster, null, 0, 1, 0); if (i == null || !i.hasNext()) throw new MongoException("no result for ismaster query?"); DBObject res = i.next(); if (i.hasNext()) throw new MongoException("what's going on"); return res; }