jar包下载地址
API文档
<pre>
<code>
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
public class MongoTest {
public static void main(String[] args) {
//Mongo mc = new Mongo("localhost", 27017);//老版本jar包的连接方式
MongoClient mongoClient = new MongoClient("localhost", 27017);//必须连接27017端口,否则无法连接
DB db = mongoClient.getDB("mydb");
DBCollection testData = db.getCollection("testData");
DBCursor cursor = testData.find();
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
mongoClient.close();
}
}
</code>
</pre>