本文整理了Java中com.mongodb.Mongo.setWriteConcern()
方法的一些代码示例,展示了Mongo.setWriteConcern()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mongo.setWriteConcern()
方法的具体详情如下:
包路径:com.mongodb.Mongo
类名称:Mongo
方法名:setWriteConcern
[英]Sets the default write concern to use for write operations executed on any DBCollection created indirectly from this instance, via a DB instance created from #getDB(String).
Note that changes to the default write concern made via this method will NOT affect the write concern of com.mongodb.client.MongoDatabase instances created via MongoClient#getDatabase(String)
[中]设置默认写入关注点,用于通过从#getDB(String)创建的DB实例,对从此实例间接创建的任何DBCollection执行写入操作。
请注意,通过此方法对默认写关注点所做的更改不会影响com的写关注点。mongodb。客户通过MongoClient#getDatabase(字符串)创建的MongoDatabase实例
代码示例来源:origin: spring-projects/spring-data-book
@Override
public Mongo mongo() throws Exception {
Mongo mongo = new Mongo();
mongo.setWriteConcern(WriteConcern.SAFE);
return mongo;
}
代码示例来源:origin: org.apache.camel/camel-mongodb-gridfs
private void setWriteReadOptionsOnConnection() {
// Set the WriteConcern
if (writeConcern != null) {
mongoConnection.setWriteConcern(writeConcern);
} else if (writeConcernRef != null) {
mongoConnection.setWriteConcern(writeConcernRef);
}
// Set the ReadPreference
if (readPreference != null) {
mongoConnection.setReadPreference(readPreference);
}
}
代码示例来源:origin: stackoverflow.com
Mongo m = new Mongo();
m.setWriteConcern(WriteConcern.SAFE);
DBCollection c = m.getDB("testdb").getCollection("collection");
Pattern pattern = Pattern.compile("Test Message");
DBObject query = QueryBuilder.start().
QueryBuilder.start("description").regex(pattern).get();
System.out.println(c.find(query).count());
代码示例来源:origin: stackoverflow.com
public class MongoRepositoryConfig extends AbstractMongoConfiguration {
@Value("${db.host.port}")
private int port;
@Value("${db.host.name}")
private String host;
@Value("${db.name}")
private String dbname;
@Override
public Mongo mongo() throws Exception {
ServerAddress serverAdress = new ServerAddress(host,port);
Mongo mongo = new MongoClient(serverAdress);
mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED);
return mongo;
}
public @Bean MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), getDatabaseName());
}
@Override
protected String getDatabaseName() {
return dbname;
}
}
代码示例来源:origin: stackoverflow.com
Mongo m = new Mongo();
m.setWriteConcern(WriteConcern.SAFE);
DBCollection c = m.getDB("test").getCollection("or-test");
c.drop();
c.insert(new BasicDBObject("a", "abba"));
c.insert(new BasicDBObject("b", "abba"));
c.insert(new BasicDBObject("a", "bbba"));
c.insert(new BasicDBObject("b", "bbba"));
Pattern pattern = Pattern.compile("^a");
DBObject query = QueryBuilder.start().or(
QueryBuilder.start("a").regex(pattern).get(),
QueryBuilder.start("b").regex(pattern).get()
).get();
System.out.println(c.find(query).count());
代码示例来源:origin: ch.epfl.bbp.nlp/bluima_mongodb
m.setWriteConcern(WriteConcern.SAFE);
代码示例来源:origin: com.lordofthejars/nosqlunit-mongodb
public MongoOperation(MongoDbConfiguration mongoDbConfiguration) {
try {
this.mongo = mongoDbConfiguration.getMongo();
this.mongo.setWriteConcern(mongoDbConfiguration.getWriteConcern());
this.mongoDbConfiguration = mongoDbConfiguration;
this.setInsertionStrategy(new DefaultInsertionStrategy());
this.setComparisonStrategy(new DefaultComparisonStrategy());
} catch (MongoException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: rystsov/mongodb-transaction-example
public static void main( String[] args ) throws UnknownHostException {
Mongo mongo = new Mongo("localhost", 27017);
mongo.setWriteConcern(WriteConcern.SAFE);
DB bank = mongo.getDB("bank");
DBCollection accounts = bank.getCollection("accounts");
DBCollection txs = bank.getCollection("txs");
Db db = new Db();
// init
Kv.KvEntity roc = db.create(accounts, (DBObject) JSON.parse("{ name : 'roc', balance : 100 }"));
Kv.KvEntity gov = db.create(accounts, (DBObject) JSON.parse("{ name : 'gov', balance : 700 }"));
Transaction transaction = new Transaction(db, db.create(txs, null));
transaction.change(accounts, roc, (DBObject) JSON.parse("{ name : 'roc', balance : 50 }"));
transaction.change(accounts, gov, (DBObject) JSON.parse("{ name : 'gov', balance : 750 }"));
transaction.commit(txs);
}
}
内容来源于网络,如有侵权,请联系作者删除!