Package com;
Import java.net.UnknownHostException;
Import Com.mongodb.DB;
Import com.mongodb.DBCollection;
Import Com.mongodb.DBCursor;
Import Com.mongodb.Mongo;
Import com.mongodb.MongoException;
Import Com.mongodb.util.JSON; /** * <B>FUNCTION:</B>MONGODB Administrative Enday Spells an example * * @author Hoojo * @createDate 2011-5-24 Juan Example 崍 02:42:29 * @file Simpl
Etest.java * @package com.hoo.test * @project MongoDB * @blog Http://blog.csdn.net/IBM_hoojo * @email hoojo_@126.com
* @version 1.0 */public class SimpleTest {/* * public static void Main (string[] args) throws Unknownhostexception, * Mongoexception {Mongo mg = new Mongo ();//Motai ヨ gallium? have fermium 凞 atabase for (String name *: Mg.getdatabasenames ()) {System.out.
println ("DbName:" + name);} * * DB db = Mg.getdb ("test");
Motai ヨ gallium? Have fermium cancel Flo boss 嗛 泦 Å? for (String name: * Db.getcollectionnames ()) {System.out.println ("CollectionName:" + name);
*} * * Dbcollection users = db.getcollection ("users"); * *//Motai ヨ gallium? Have Fermium ecf 暟 is? Dbcursor cur = Users. find (); while (Cur.hasnext ()) {* SYSTEM.OUT.PRINTLN (Cur.next ());}
System.out.println (Cur.count ());
* SYSTEM.OUT.PRINTLN (Cur.getcursorid ()); * SYSTEM.OUT.PRINTLN (json.serialize (cur));
} */public static void main (string[] args) throws Exception {Mongo mg = new Mongo ();
Query all database for (String name:mg.getDatabaseNames ()) {System.out.println ("DbName:" + name);
} DB db = Mg.getdb ("test"); Queries all clustered collections for (String Name:db.getCollectionNames ()) {System.out.println ("CollectionName:" + NA
ME);
} dbcollection users = Db.getcollection ("users");
Query all data dbcursor cur = users.find ();
while (Cur.hasnext ()) {System.out.println (Cur.next ());
} System.out.println (Cur.count ());
System.out.println (Cur.getcursorid ());
System.out.println (json.serialize (cur)); }
}