假设我已使用MongoDB Java驱动程序创建以下内容:
public class MongoDBTest {
public static final String MY_MONGO = "MyMongo";
public static final String ROOT = "Root";
public static void main(String[] args) {
MongoDBTest test = new MongoDBTest();
test.createDocument();
}
public void createDocument() {
MongoClient client = null;
DB db = null;
try {
client = new MongoClient( "localhost", 27017 );
db = client.getDB( MY_MONGO );
}
catch (UnknownHostException ignored) {
}
System.out.println( "Connected to database." );
assert db != null;
DBObject document = new BasicDBObject( "name", "Me" ).append( "Place", "NYC" );
System.out.println("Inserting document: "+document);
DBCollection collection = db.collectionExists( ROOT ) ? db.getCollection( ROOT ) : db.createCollection(
ROOT,
document
);
collection.insert( document );
}
}
如何将此数据库转换为运行端口为27017,27018和27019的DB的副本集? 如果我无法将其转换为副本集,如何在开头创建副本集?