In the replica set cluster, how do i read files from GridFS of a secondary?

已查看 204 次
跳至第一个未读帖子

一球成名

未读,
2011年7月25日 21:59:122011/7/25
收件人 mongodb-user
I got an Exception "not master" when i read from the secondary.
In the GridFS structure method, when the files collections count less
then 1000, mongodb will to ensure standard indexes. but secondary is
not allow write operations.
so, how do i read files from a secondary?

Robert Stam

未读,
2011年7月25日 22:23:522011/7/25
收件人 mongodb-user
Which driver are you using (and which version)?

一球成名

未读,
2011年7月25日 22:28:002011/7/25
收件人 mongodb-user
mongo-java-driver-2.5.jar

On 7月26日, 上午10时23分, Robert Stam <rstam10...@gmail.com> wrote:
> Which driver are you using (and which version)?
>
> On Jul 25, 9:59 pm, 一球成名 <mache...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I got an Exception "not master" when ireadfrom the secondary.
> > In the GridFS structure method, when thefilescollections count less

Eliot Horowitz

未读,
2011年7月26日 00:43:242011/7/26
收件人 mongod...@googlegroups.com
Set slaveOk on the DB you pass to GridFS constructor. 

2011/7/25 一球成名 <mach...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


一球成名

未读,
2011年7月26日 01:39:542011/7/26
收件人 mongodb-user
Still get the Exception.

On 7月26日, 下午12时43分, Eliot Horowitz <el...@10gen.com> wrote:
> Set slaveOk on the DB you pass to GridFS constructor.
>
> 2011/7/25 一球成名 <mache...@gmail.com>

Eliot Horowitz

未读,
2011年7月26日 01:40:572011/7/26
收件人 mongod...@googlegroups.com
Can you send the code and exact error?

2011/7/26 一球成名 <mach...@gmail.com>

一球成名

未读,
2011年7月26日 01:58:362011/7/26
收件人 mongodb-user
public FileTest(String cfgPath) {
try {
MemProperties.init(cfgPath);
MongoOptions mongoOptions = new MongoOptions();
mongoOptions.slaveOk = true;
mongoOptions.connectionsPerHost =
Integer.parseInt(MemProperties
.getValue("pool_size"));
ServerAddress address = new ServerAddress(MemProperties
.getValue("mongo_ip"),
Integer.parseInt(MemProperties
.getValue("mongo_port")));
mongo = new Mongo(address, mongoOptions);
// mongo.slaveOk();

picList = ImageReader.readFromDB();
db = mongo.getDB(MemProperties.getValue("mongo_dbname"));
db.slaveOk();
} catch (Exception e) {
e.printStackTrace();
}
}

public void queryFromGridFS(int id) throws Exception {
BasicDBObject query = new BasicDBObject();
query.put("id", id);
GridFS gridFS = new GridFS(db,
MemProperties.getValue("file_bucket"));
GridFSDBFile dbFile = gridFS.findOne(query);
if (dbFile != null) {
dbFile.writeTo(new ByteArrayOutputStream());
System.out.println(gridFS.getDB().getMongo().getAddress());
} else {
System.out.println("miss");
}
// dbFile.writeTo("e:\\test\\" + dbFile.getFilename());
}

Exception in thread "main" com.mongodb.MongoException: not master
at com.mongodb.CommandResult.getException(CommandResult.java:82)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:116)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:
131)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:153)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:137)
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:77)
at mongo.test.FileTest.queryFromGridFS(FileTest.java:139)
at mongo.test.FileTest.main(FileTest.java:63)


On 7月26日, 下午1时40分, Eliot Horowitz <el...@10gen.com> wrote:
> Can you send the code and exact error?
>
> 2011/7/26 一球成名 <mache...@gmail.com>

Nat

未读,
2011年7月26日 08:29:162011/7/26
收件人 mongod...@googlegroups.com
Sounds like a bug that ensureIndex goes to secondaries. You might want to file a bug report.

一球成名

未读,
2011年8月4日 02:33:132011/8/4
收件人 mongodb-user
回复全部
回复作者
转发
0 个新帖子