Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Java clusterMonitor repro
import com.mongodb.*;
import com.mongodb.util.JSON;
import com.mongodb.util.JSONSerializers;
import org.bson.BSON;
import org.bson.BSONObject;
import org.bson.types.ObjectId;
import org.json.JSONObject;
import org.junit.Test;
import java.util.*;
public class ClusterMonitorRepro {
public static void main(String[] args) throws Exception {
final MongoCredential credential = MongoCredential.createScramSha1Credential("usernameWithClusterMonitorRole", "admin", "password".toCharArray());
final MongoClient client = new MongoClient(new ServerAddress("localhost", 6000), Collections.singletonList(credential));
try {
final DBCollection collection = client.getDB("admin").getCollection("system.profile");
try (final DBCursor cursor = collection.find()
.sort(new BasicDBObject("$natural", -1))
.setReadPreference(ReadPreference.primaryPreferred())) {
while(cursor.hasNext()) {;
} finally {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.