##安裝和執行MongoDB
mongod 命令來執行MongoDB 伺服器,如下所示-
##C:\Users\Tutorialspoint>mongod --dbpath "C:\data"
> use myDatabase; switched to db myDatabase
安裝Java MongoDB驅動程式
pom.xml# 檔案。<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.2</version>
</dependency>
實例
import com.mongodb.MongoClient; public class ConnectToDB { public static void main( String args[] ) { //Creating a MongoDB client MongoClient mongo = new MongoClient( "localhost" , 27017 ); //Accessing the database mongo.getDatabase("myDatabase"); System.out.println("Connected to the database successfully"); } }
以上是如何設定MongoDB Java環境?的詳細內容。更多資訊請關注PHP中文網其他相關文章!