leewill
Apr 21st, 2011, 09:08 AM
I'm using Spring Mongo 1.0.0M2. I tried to update a property in a document and it failed when query by ID. This is the mongo template configuration:
@Override
public Mongo mongo() throws Exception {
ServerAddress address = new ServerAddress( "127.0.0.1" , 27017);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost=10;
options.threadsAllowedToBlockForConnectionMultipli er=5;
options.maxWaitTime=6000;
options.connectTimeout=0;
options.socketTimeout=0;
Mongo mongo = new Mongo(address, options);
return mongo;
}
@Override
public MongoTemplate mongoTemplate() throws Exception {
MongoTemplate mongoTemplate = new MongoTemplate(mongo(), "ecl");
mongoTemplate.setMongoConverter(mappingMongoConver ter());
mongoTemplate.setUsername(USERNAME);
mongoTemplate.setPassword(PASSWORD);
return mongoTemplate;
}
// public String getMappingBasePackage() {
// return "dist.bo";
// }
The injected MongoOperations works for save document, update entire document. It also works fine when:
mongoTemplate.updateFirst("entityCollectionName",
query(where("name").is("object name")),
update("deleted", true));
but never work if the query is
query(whereId().is(the_document_id)),
The funny thing is, retrieving document by id with such query works fine:
mongoTemplate.findOne(query(whereId().is(the_docum ent_id)),
MyDoc.class);
I never found any tutorial/reference talking about update a property by query ID.
Did I miss something?
@Override
public Mongo mongo() throws Exception {
ServerAddress address = new ServerAddress( "127.0.0.1" , 27017);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost=10;
options.threadsAllowedToBlockForConnectionMultipli er=5;
options.maxWaitTime=6000;
options.connectTimeout=0;
options.socketTimeout=0;
Mongo mongo = new Mongo(address, options);
return mongo;
}
@Override
public MongoTemplate mongoTemplate() throws Exception {
MongoTemplate mongoTemplate = new MongoTemplate(mongo(), "ecl");
mongoTemplate.setMongoConverter(mappingMongoConver ter());
mongoTemplate.setUsername(USERNAME);
mongoTemplate.setPassword(PASSWORD);
return mongoTemplate;
}
// public String getMappingBasePackage() {
// return "dist.bo";
// }
The injected MongoOperations works for save document, update entire document. It also works fine when:
mongoTemplate.updateFirst("entityCollectionName",
query(where("name").is("object name")),
update("deleted", true));
but never work if the query is
query(whereId().is(the_document_id)),
The funny thing is, retrieving document by id with such query works fine:
mongoTemplate.findOne(query(whereId().is(the_docum ent_id)),
MyDoc.class);
I never found any tutorial/reference talking about update a property by query ID.
Did I miss something?