Java 操作MongoDB 基本操作
需要下载驱动,并且依赖不多说:
看代码:
package com.payment;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
//不需要认证
public class LoginMongoDB {
/**
* 获得无密码验证的client
* @param ip
* @param port
* @return
*/
public static MongoClient getClient(String ip,int port){
MongoClient client=null;
try {
MongoClientOptions.Builder build