本文整理了Java中com.mongodb.Mongo.<init>()
方法的一些代码示例,展示了Mongo.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mongo.<init>()
方法的具体详情如下:
包路径:com.mongodb.Mongo
类名称:Mongo
方法名:<init>
[英]Creates a Mongo instance based on a (single) mongodb node (localhost, default port)
[中]
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Creates a Mongo instance based on the URI.
*
* @return a new Mongo instance. There is no caching, so each call will create a new instance, each of which must be closed manually.
* @throws MongoException if there's a failure
*/
@SuppressWarnings("deprecation")
public Mongo connect() {
// Note: we can't change this to new MongoClient(this) as that would silently change the default write concern.
return new Mongo(this);
}
代码示例来源:origin: spring-projects/spring-data-book
@Override
public Mongo mongo() throws Exception {
Mongo mongo = new Mongo();
mongo.setWriteConcern(WriteConcern.SAFE);
return mongo;
}
代码示例来源:origin: stackoverflow.com
mongodExe = runtime.prepare(new MongodConfig(Version.V2_3_0, 12345, Network.localhostIsIPv6()));
mongod = mongodExe.start();
mongo = new Mongo("localhost", 12345);
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws UnknownHostException,
MongoException {
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("yeahMongo");
Employee employee = new Employee();
employee.setNo(1L);
employee.setName("yogesh");
DBCollection employeeCollection = null ;
employeeCollection = db.getCollection(Employee.COLLECTION_NAME);
employeeCollection.save(employee);
System.err.println(employeeCollection.findOne());
}
代码示例来源:origin: stackoverflow.com
Mongo mongo = new Mongo();
DBObject ping = new BasicDBObject("ping", "1");
try {
mongo.getDB("dbname").command(ping);
} catch (MongoException e) {
...
}
代码示例来源:origin: stackoverflow.com
Mongo m = new Mongo( "localhost" , 27017 );
DB db = m.getDB( "mydb" );
代码示例来源:origin: stackoverflow.com
Mongo mongo = new Mongo();
try {
mongo.getConnector().getDBPortPool(mongo.getAddress()).get().ensureOpen();
} catch (Exception e) {
...
}
代码示例来源:origin: stackoverflow.com
Mongo m = new Mongo("localhost", 27017);
DB db = m.getDB("test");
DBCollection myColl = db.getCollection("myCollection");
BasicDBObject docToInsert = new BasicDBObject("resourceID", "3");
docToInsert.put("resourceName", "Foo Test3");
BasicDBObject updateQuery = new BasicDBObject("_id", "1");
updateQuery.put("itemList.itemID", "1");
BasicDBObject updateCommand = new BasicDBObject("$push", new BasicDBObject("itemList.$.resources", docToInsert));
myColl.update(updateQuery, updateCommand);
System.out.println(myColl.findOne().toString());
代码示例来源:origin: stackoverflow.com
Mongo mongo = new Mongo("127.0.0.1");
DB db = mongo.getDB("mydbid");
DBCollection collection;
if (db.collectionExists("mycollection")) {
collection = db.getCollection("mycollection");
} else {
DBObject options = BasicDBObjectBuilder.start().add("capped", true).add("size", 2000000000l).get();
collection = db.createCollection("mycollection", options);
}
}
代码示例来源:origin: stackoverflow.com
mongoTemplate = new MongoTemplate(new Mongo(host, port), db,
new UserCredentials(username, password));
代码示例来源:origin: stackoverflow.com
public class Foo extends Bar {
private Mongo mongo;
public Foo() throws SomeException {
mongo = new Mongo();
}
// stuff goes here
}
代码示例来源:origin: org.mongodb/mongodb-driver
/**
* Creates a Mongo instance based on the URI.
*
* @return a new Mongo instance. There is no caching, so each call will create a new instance, each of which must be closed manually.
* @throws MongoException if there's a failure
*/
@SuppressWarnings("deprecation")
public Mongo connect() {
// Note: we can't change this to new MongoClient(this) as that would silently change the default write concern.
return new Mongo(this);
}
代码示例来源:origin: stackoverflow.com
private DBCursor curs;
public Nextstud() {
Mongo s = new Mongo();
DB db = s.getDB( "omrs1" );
DBCollection coll = db.getCollection("Student") ;
代码示例来源:origin: stackoverflow.com
@Service
public class MongoService {
private final Mongo mongo;
private final String database;
private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);
@bean
public MongoService(@Nonnull final @Value("#{ systemProperties['host']}") String host, @Nonnull final @Value("#{ systemProperties['port']}") int port, @Nonnull final @Value("#{ systemProperties['database']}") String db) throws UnknownHostException {
LOGGER.info("host=" + host + ", port=" + port + ", database=" + db);
mongo = new Mongo(host, port);
database = db;
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-mongomk
/**
* Constructs a new {@code MongoConnection}.
*
* @param host The host address.
* @param port The port.
* @param database The database name.
* @throws Exception If an error occurred while trying to connect.
*/
public MongoConnection(String host, int port, String database) throws Exception {
mongo = new Mongo(host, port);
db = mongo.getDB(database);
}
代码示例来源:origin: stackoverflow.com
Mongo m = new Mongo("localhost", 27017);
DB db = m.getDB("test");
DBCollection myColl = db.getCollection("collection");
ArrayList<String> newResourceIDList = new ArrayList<String>();
newResourceIDList.add("Something");
newResourceIDList.add("new");
BasicDBObject myQuery = new BasicDBObject("_id", "1");
myQuery.put("projectList.projectID", "Spring");
BasicDBObject myUpdate = new BasicDBObject("$set", new BasicDBObject("projectList.$.resourceIDList", newResourceIDList));
myColl.update(myQuery, myUpdate);
System.out.println(myColl.findOne().toString());
代码示例来源:origin: io.jeo/jeo-mongo
public DB connect() throws IOException {
ServerAddress server = new ServerAddress(host, port);
Mongo mongo = new Mongo(server);
DB database = mongo.getDB(db);
database.authenticate(user, passwd != null ? passwd.get(): new char[]{});
return database;
}
}
代码示例来源:origin: zscott/MultiBitExchange
public Mongo newMongo() throws UnknownHostException, MongoException {
return new Mongo(new ServerAddress(
mongodProcess.getConfig().net().getServerAddress(),
mongodProcess.getConfig().net().getPort()));
}
代码示例来源:origin: stackoverflow.com
Mongo mongo = new Mongo();
DB db = mongo.getDB("test");
DBCollection people = db.getCollection("people");
BasicDBObject name = new BasicDBObject();
name.put("FirstName", "Ahmad");
name.put("LastName", "Khan");
BasicDBObject person = new BasicDBObject();
person.put("ID", 23);
person.put("Name", name);
people.insert(person);
代码示例来源:origin: net.csdn/MongoMongo
public MongoMongo(CSDNMongoConfiguration csdnMongoConfiguration) throws Exception {
this.mongoConfiguration = csdnMongoConfiguration;
this.mongo = new Mongo(settings().get(mode() + ".datasources.mongodb.host", defaultHostName), mongoConfiguration.settings.getAsInt(mode() + ".datasources.mongodb.port", defaultHostPort));
dbName = settings().get(mode() + ".datasources.mongodb.database", defaultDBName);
}
内容来源于网络,如有侵权,请联系作者删除!