Crates.io | oplog |
lib.rs | oplog |
version | 0.3.0 |
source | src |
created_at | 2017-01-01 16:17:13.270673 |
updated_at | 2018-02-20 10:20:49.57847 |
description | Library for iterating over a MongoDB replica set oplog. |
homepage | |
repository | https://github.com/mudge/oplog |
max_upload_size | |
id | 7881 |
size | 30,532 |
A Rust library for iterating over a MongoDB replica set oplog.
Current version: 0.3.0
Supported Rust versions: 1.14
Install Oplog by adding the following to your Cargo.toml
:
oplog = "0.3.0"
#[macro_use]
extern crate bson;
extern crate mongodb;
extern crate oplog;
use mongodb::{Client, ThreadedClient};
use oplog::{Operation, Oplog, OplogBuilder};
fn main() {
let client = Client::connect("localhost", 27017).expect("Failed to connect to MongoDB.");
if let Ok(oplog) = Oplog::new(&client) {
for operation in oplog {
match operation {
Operation::Noop { timestamp, .. } => println!("No-op at {}", timestamp),
Operation::Insert { timestamp, .. } => println!("Insert at {}", timestamp),
Operation::Update { timestamp, .. } => println!("Update at {}", timestamp),
Operation::Delete { timestamp, .. } => println!("Delete at {}", timestamp),
Operation::Command { timestamp, .. } => println!("Command at {}", timestamp),
Operation::ApplyOps { timestamp, .. } => println!("ApplyOps at {}", timestamp),
}
}
}
// Or, if you want to filter out certain operations:
if let Ok(oplog) = OplogBuilder::new(&client).filter(Some(doc! { "op" => "i" })).build() {
for insert in oplog {
println!("{}", insert);
}
}
}
Full API documentation is available at http://mudge.name/oplog
And many thanks to Ryman for his help along the way.
Copyright © 2016-2018 Paul Mucur.
Distributed under the MIT License.