以下是Java代码示例:
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoDatabase;
public class MongoDatabaseConnection {
public static MongoDatabase getMongoDatabase() {
MongoClientURI uri = new MongoClientURI("mongodb://localhost:27017");
MongoClient client = new MongoClient(uri);
MongoDatabase database = client.getDatabase("myDatabase");
return database;
}
}