FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mongo-java-driver/examples/ReadOplog.java at master · alphaadidas/mongo-java-driver · GitHub
alphaadidas
/
mongo-java-driver
Public
forked from
mongodb/mongo-java-driver
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mongo-java-driver
/
examples
/
ReadOplog.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (36 loc) · 1.35 KB
Breadcrumbs
mongo-java-driver
/
examples
/
ReadOplog.java
Copy path
File metadata and controls
46 lines (36 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ReadOplog.java
package
examples
;
import
com
.
mongodb
.*;
import
org
.
bson
.
types
.*;
import
java
.
util
.*;
public
class
ReadOplog
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Mongo
m
=
new
Mongo
();
DB
local
=
m
.
getDB
(
"local"
);
DBCollection
oplog
=
local
.
getCollection
(
"oplog.$main"
);
DBObject
last
=
null
;
{
DBCursor
lastCursor
=
oplog
.
find
().
sort
(
new
BasicDBObject
(
"$natural"
, -
1
) ).
limit
(
1
);
if
( !
lastCursor
.
hasNext
() ){
System
.
out
.
println
(
"no oplog!"
);
return
;
}
last
=
lastCursor
.
next
();
}
BSONTimestamp
ts
= (
BSONTimestamp
)
last
.
get
(
"ts"
);
System
.
out
.
println
(
"starting point: "
+
ts
);
while
(
true
){
System
.
out
.
println
(
"starting at ts: "
+
ts
);
DBCursor
cursor
=
oplog
.
find
(
new
BasicDBObject
(
"ts"
,
new
BasicDBObject
(
"$gt"
,
ts
) ) );
cursor
.
addOption
(
Bytes
.
QUERYOPTION_TAILABLE
);
cursor
.
addOption
(
Bytes
.
QUERYOPTION_AWAITDATA
);
while
(
cursor
.
hasNext
() ){
DBObject
x
=
cursor
.
next
();
ts
= (
BSONTimestamp
)
x
.
get
(
"ts"
);
System
.
out
.
println
(
"
\t
"
+
x
);
}
Thread
.
sleep
(
1000
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL