Package com.mongodb

Examples of com.mongodb.MongoClient


public class Hinting {

    public static void main(String[] args) throws UnknownHostException {

        MongoClient client = new MongoClient();
        DB db = client.getDB("test");

        BasicDBObject query = new BasicDBObject("a", 40000);
        query.append("b",40000);
        query.append("c",40000);
View Full Code Here


import java.net.UnknownHostException;
import java.util.Arrays;

public class WriteConcernTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        client.setWriteConcern(WriteConcern.JOURNALED);

        DB db = client.getDB("course");
        db.setWriteConcern(WriteConcern.JOURNALED);
        DBCollection coll = db.getCollection("write.test");
        coll.setWriteConcern(WriteConcern.JOURNALED);

        coll.drop();
View Full Code Here

import java.net.UnknownHostException;
import java.util.Arrays;

public class ReplicaSetFailoverTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        DBCollection test = client.getDB("course").getCollection("replica.test");
        test.drop();

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            for (int retries = 0; retries <= 2; retries++) {
                try {
View Full Code Here

import java.util.Arrays;

public class ReplicaSetTest {

    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        DBCollection test = client.getDB("course").getCollection("replica.test");
        test.drop();

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            test.insert(new BasicDBObject("_id", i));
            System.out.println("Inserted document: " + i);
View Full Code Here

import java.net.UnknownHostException;
import java.util.Arrays;

public class ReadPreferenceTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));
        client.setReadPreference(ReadPreference.primary());

        DB db = client.getDB("course");
        db.setReadPreference(ReadPreference.primary());
        DBCollection coll = db.getCollection("write.test");
        coll.setReadPreference(ReadPreference.primaryPreferred());

        DBCursor cursor = coll.find().setReadPreference(ReadPreference.nearest());
View Full Code Here

    public static void main(String[] args) throws IOException, ParseException {
        final String screenName = args.length > 0 ? args[0] : "10gen";

        List<DBObject> tweets = getLatestTweets(screenName);

        MongoClient client = new MongoClient();
        DBCollection tweetsCollection = client.getDB("course").getCollection("twitter");
//        tweetsCollection.drop();

        for (DBObject cur : tweets) {
            cur.put("screen_name", screenName);
            massageTweetId(cur);
            massageTweet(cur);
            tweetsCollection.update(new BasicDBObject("_id", cur.get("_id")), cur, true, false);
        }

        System.out.println("Tweet count: " + tweetsCollection.count());

        client.close();
    }
View Full Code Here

public class GridFSTest {

    public static void main(String[] args) throws UnknownHostException, FileNotFoundException, IOException {

        MongoClient client = new MongoClient();
        DB db = client.getDB("course");
        FileInputStream inputStream = null;


        GridFS videos = new GridFS(db, "videos"); // returns GridFS bucket named "videos"
View Full Code Here

import java.util.Arrays;
import java.util.List;

public class hw3_1 {
    public static void main(String[] args) throws UnknownHostException {
        MongoClient mongoClient = new MongoClient();
        DB school = mongoClient.getDB("school");
        DBCollection studentsCollection = school.getCollection("students");

        DBCursor students = studentsCollection.find();

        DBObject student = null;
View Full Code Here

import java.net.UnknownHostException;

public class HelloWorldMongoDBStyle {
    public static void main(String[] args) throws UnknownHostException {
        MongoClient client =
                new MongoClient(new ServerAddress("localhost", 27017));

        DB database = client.getDB("course");
        DBCollection collection = database.getCollection("hello");

        DBObject document = collection.findOne();
        System.out.println(document);
    }
View Full Code Here

    public static void main(String[] args) throws UnknownHostException {
        final Configuration configuration = new Configuration();
        configuration.setClassForTemplateLoading(
                HelloWorldSparkFreemarkerStyle.class, "/");

        MongoClient client = new MongoClient(new ServerAddress("localhost", 27017));

        DB database = client.getDB("course");
        final DBCollection collection = database.getCollection("hello");


        Spark.get(new Route("/") {
            @Override
View Full Code Here

TOP

Related Classes of com.mongodb.MongoClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.