[java]代码库
import com.mongodb.Mongo;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.MongoAdmin;
Mongo db = new Mongo(“mydb”);
Mongo db = new Mongo(“localhost”, “mydb”);
Mongo db = new Mongo(“localhost”, 27017, “mydb”);
boolean auth = db.authenticate(userName, password);
//每个数据库都存在零个或多个集合
Set colls = db.getCollectionNames();
for(String s : colls){
System.out.println(s);
}
//查询
BasicDBObject query = new BasicDBObject();
query.put(“i”, new BasicDBObject(“$gt”, 20).append(“$lte”, 30));
cur = coll.find(query);
while(cur.hasNext()){
System.out.println(cur.next());
}