首页 新闻 搜索 专区 学院

mongoDB连接服务器问题,各位大神看看咋回事?

0
[已解决问题] 解决于 2014-12-25 14:35

import com.mongodb.DB;//加载MongoDB的java驱动
import com.mongodb.MongoException;
import com.mongodb.gridfs.GridFSFile;

import java.io.File;
import java.io.IOException;


import java.util.Date;

import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSInputFile;
import com.mongodb.*;
public class connectMongoDB {
public static void main(String[] args) throws MongoException, IOException {
try{
long start = new Date().getTime();
Mongo m = new Mongo("192.168.10.221", 27017);
DB db = m.getDB("test");
//db.authenticate("test", "123".toCharArray());
File f = new File("D:\\2010.pdf");
GridFS myFS = new GridFS(db);
GridFSInputFile inputFile = myFS.createFile(f);
inputFile.save();
long endTime = new Date().getTime();
System.out.println(endTime-start);
System.out.println((endTime - start) / 10000000);
}

catch(Exception e){
e.printStackTrace();
}
}
}

问题补充:

com.mongodb.MongoException: Index with name: files_id_1_n_1 already exists with different options
at com.mongodb.CommandResult.getException(CommandResult.java:82)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:116)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:126)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:148)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:132)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:255)
at com.mongodb.DBApiLayer$MyCollection.createIndex(DBApiLayer.java:347)
at com.mongodb.DBCollection.ensureIndex(DBCollection.java:437)
at com.mongodb.DBCollection.ensureIndex(DBCollection.java:385)
at com.mongodb.gridfs.GridFS.<init>(GridFS.java:79)
at com.mongodb.gridfs.GridFS.<init>(GridFS.java:58)
at connectMongoDB.main(connectMongoDB.java:22)

LiloT的主页 LiloT | 初学一级 | 园豆:6
提问于:2014-04-16 12:04
< >
分享
最佳答案
0

解决了,驱动的问题

LiloT | 初学一级 |园豆:6 | 2014-04-16 13:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册