问题描述
在一台电脑上开个3个端口,Replica Set模式,刚刚新建了一个新DB和新的collection,往这个collection中插入3000多条数据,第一次只能插入1600多条,删库,然后第二次1700多条,第三次1800多条。电脑是32位的老机器,这3000多条数据大小也就是125Kb。用的还java的API。
Mongo mongo = null;MongoURI uri=new MongoURI('mongodb://localhost:27017,localhost:27018,localhost:27019');mongo=new Mongo.Holder().connect(uri);mongo.slaveOk();DB db=mongo.getDB('words');DBCollection co= db.getCollection('test');String pa='c:111.txt';FileReader fr;fr = new FileReader(pa);BufferedReader in=new BufferedReader(fr); String line=null;while((line=in.readLine())!=null) { BasicDBObject document = new BasicDBObject(); String datas[]=line.split('-'); int id=Integer.parseInt(datas[0]); document.put('_id',id); document.put('name',datas[1]); co.insert(document); System.out.println(id+' '+datas[1]);}
问题解答
回答1:Mongo是非安全写入的,要确保没问题最好getLastError

