5
5
"fmt"
6
6
"log"
7
7
"net"
8
+ s "strings"
8
9
"sync"
9
10
"time"
10
11
@@ -88,7 +89,7 @@ func (c *Connection) Databases() ([]string, error) {
88
89
var slice []string
89
90
90
91
for _ , dbname := range dbnames {
91
- if dbname != "local" && dbname != "admin" {
92
+ if dbname == c . config . Database {
92
93
slice = append (slice , dbname )
93
94
}
94
95
}
@@ -104,7 +105,7 @@ func (c *Connection) databaseRegExs() ([]bson.RegEx, error) {
104
105
var slice []bson.RegEx
105
106
106
107
for _ , dbname := range dbnames {
107
- if dbname != "local" && dbname != "admin" {
108
+ if dbname == c . config . Database {
108
109
slice = append (slice , bson.RegEx {Pattern : dbname + ".*" })
109
110
}
110
111
}
@@ -179,6 +180,7 @@ func (c *Connection) SyncOplog(dst *Connection) error {
179
180
// apply the operation
180
181
opsToApply := []Oplog {oplogEntry }
181
182
err := dst .Session .Run (bson.M {"applyOps" : opsToApply }, & applyOpsResponse )
183
+
182
184
if err != nil {
183
185
return fmt .Errorf ("error applying ops: %v" , err )
184
186
}
@@ -198,7 +200,8 @@ func (c *Connection) SyncOplog(dst *Connection) error {
198
200
}
199
201
}
200
202
201
- fmt .Println ("Tailing..." )
203
+ fmt .Println ("Tailing....." )
204
+
202
205
iter = oplog .Find (tail_query ).Tail (1 * time .Second )
203
206
for {
204
207
for iter .Next (& oplogEntry ) {
@@ -207,11 +210,46 @@ func (c *Connection) SyncOplog(dst *Connection) error {
207
210
log .Printf ("skipping no-op for namespace `%v`" , oplogEntry .Namespace )
208
211
continue
209
212
}
210
- opCount ++
213
+
214
+ if ! s .Contains (oplogEntry .Namespace , c .config .Database + "." ) {
215
+ log .Printf ("skipping namespace `%v`" , oplogEntry .Namespace )
216
+ continue
217
+ }
218
+
219
+ // check collection against config
220
+ collection := s .Split (oplogEntry .Namespace , "." )[1 ]
221
+
222
+ isCollectionMatch := false
223
+ for _ , permittedCollection := range c .config .Collections {
224
+ if collection == permittedCollection {
225
+ isCollectionMatch = true
226
+ }
227
+ }
228
+
229
+ if ! isCollectionMatch {
230
+ log .Printf ("skipping collection `%v`" , oplogEntry .Namespace )
231
+ continue
232
+ }
233
+
234
+ oplogEntry .Namespace = dst .config .Database + "." + collection
235
+
236
+ if false {
237
+ fmt .Println ("\n " )
238
+ fmt .Println ("****************************** %v" , oplogEntry .HistoryID )
239
+ fmt .Println ("****************************** %v" , oplogEntry .Namespace )
240
+ fmt .Println ("****************************** %v" , oplogEntry .Object )
241
+ fmt .Println ("****************************** %v" , oplogEntry .Operation )
242
+ fmt .Println ("****************************** %v" , oplogEntry .Query )
243
+ fmt .Println ("****************************** %v" , oplogEntry .Timestamp )
244
+ fmt .Println ("****************************** %v" , oplogEntry .Version )
245
+ fmt .Println ("%v" , oplogEntry .Namespace )
246
+ }
211
247
212
248
// apply the operation
249
+ opCount ++
213
250
opsToApply := []Oplog {oplogEntry }
214
251
err := dst .Session .Run (bson.M {"applyOps" : opsToApply }, & applyOpsResponse )
252
+
215
253
if err != nil {
216
254
return fmt .Errorf ("error applying ops: %v" , err )
217
255
}
0 commit comments