Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AppTag
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
AppTag
Commits
6fa953b3
Commit
6fa953b3
authored
Jul 18, 2019
by
jinfeng.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
01e994a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
18 deletions
+16
-18
GetPackageFromMongo.java
...n/java/com/mobvista/apptag/utils/GetPackageFromMongo.java
+16
-18
No files found.
src/main/java/com/mobvista/apptag/utils/GetPackageFromMongo.java
View file @
6fa953b3
package
com
.
mobvista
.
apptag
.
utils
;
package
com
.
mobvista
.
apptag
.
utils
;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClientSettings
;
import
com.mongodb.MongoClientOptions
;
import
com.mongodb.ReadPreference
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.*
;
import
com.mongodb.client.MongoCursor
;
import
com.mongodb.client.MongoDatabase
;
import
com.mongodb.client.model.Filters
;
import
com.mongodb.client.model.Filters
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.bson.Document
;
import
org.bson.Document
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @package: com.mobvista.apptag.utils
* @package: com.mobvista.apptag.utils
...
@@ -25,22 +23,22 @@ import java.util.Set;
...
@@ -25,22 +23,22 @@ import java.util.Set;
public
class
GetPackageFromMongo
{
public
class
GetPackageFromMongo
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
try
{
try
{
MongoClientOptions
.
Builder
builder
=
new
MongoClientOptions
.
Builder
();
String
mongoUrl
=
"internal-beijing-adServerMongo-virginia-1390640500.us-east-1.elb.amazonaws.com"
;
// build the connection options,set the max wait time in (ms)
builder
.
readPreference
(
ReadPreference
.
primaryPreferred
())
.
retryWrites
(
true
)
.
maxConnectionIdleTime
(
6000
);
MongoClientOptions
opts
=
builder
.
build
();
// MongoCredential credential2 = MongoCredential.createCredential("username", "databasename",password2);
//add your option to the connection
// MongoClientOptions.Builder builder = new MongoClientOptions.Builder()
MongoClientSettings
settings
=
MongoClientSettings
.
builder
()
.
retryWrites
(
true
)
.
applyToConnectionPoolSettings
(
builder
->
builder
.
maxConnectionIdleTime
(
6000
,
TimeUnit
.
MILLISECONDS
))
.
applyToSslSettings
(
builder
->
builder
.
enabled
(
true
))
.
applyToClusterSettings
(
builder
->
{
builder
.
hosts
(
Arrays
.
asList
(
new
ServerAddress
(
mongoUrl
,
27017
)));
}).
build
();
// MongoClient mongoClient = new MongoClient(new ServerAddress("server ip",27017), Arrays.asList(credential2),opts);
// MongoClient mongoClient = new MongoClient(new ServerAddress("server ip",27017), Arrays.asList(credential2),opts);
// 连接到 mongodb 服务
// 连接到 mongodb 服务
String
mongoUrl
=
"internal-beijing-adServerMongo-virginia-1390640500.us-east-1.elb.amazonaws.com"
;
MongoClient
mongoClient
=
new
MongoClient
(
new
ServerAddress
(
mongoUrl
,
27017
),
opt
s
);
MongoClient
mongoClient
=
MongoClients
.
create
(
setting
s
);
// 连接到数据库
// 连接到数据库
MongoDatabase
mongoDatabase
=
mongoClient
.
getDatabase
(
"new_adn"
);
MongoDatabase
mongoDatabase
=
mongoClient
.
getDatabase
(
"new_adn"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment