Example usage for com.mongodb DBCursor size

List of usage examples for com.mongodb DBCursor size

Introduction

In this page you can find the example usage for com.mongodb DBCursor size.

Prototype

public int size() 

Source Link

Document

Counts the number of objects matching the query this does take limit/skip into consideration

Usage

From source file:tango.mongo.MongoConnector.java

License:Open Source License

public synchronized int getObjectCount(ObjectId nucleusId, int channelIdx) {
    BasicDBObject query = new BasicDBObject("nucleus_id", nucleusId).append("channelIdx", channelIdx);
    DBCursor cursor = object3D.find(query).sort(new BasicDBObject("idx", 1));
    int nb = cursor.size();
    cursor.close();//  w ww  .  j a  va2s  .c om
    return nb;
}

From source file:twitterprojectwithoutmaven.Statistics.java

public void StatisticsB() {
    //for each stalked user
    DBCursor users = dbAdapter.getInstance().getStalkedUsers();
    System.out.println("users: " + users.size());

    int c = 0;//userCounter
    while (c < start && users.hasNext()) {
        users.next();//  w  ww . j  av a 2s. com
        lastrow++;
        c++;//Start analyzing from start User (start 0:users.count)
    }

    while (users.hasNext()) {
        DBObject obj = (DBObject) users.next();
        DBUser user = new DBUser(obj);// Get User obj
        //get user's tweets
        DBUserStat stat = new DBUserStat(user.getID());

        dublist = new ArrayList<>();// simmilar tweets per tweet

        //for each user's tweet
        DBCursor userTweets = dbAdapter.getInstance().getStalkedUserTweets(user.getID());
        System.out.println("user: " + user.getID() + " tweets:" + userTweets.size());
        int count = 0, count2 = 0;// test Counter, and tweet counter
        while (userTweets.hasNext()) {

            DBObject next = userTweets.next();
            DBTweet tweet = new DBTweet(next);

            if (testMode) {

                if (count >= MaxTweets) {
                    break;
                }
                count++;
            }
            // get data from the tweet and add it to userStats
            stat.setNum_simple_tweets(stat.getNum_simple_tweets() + tweet.isASimpleTweet());
            stat.setNum_reTweets(stat.getNum_reTweets() + tweet.isaReTweet());
            stat.setNum_replies(stat.getNum_replies() + tweet.isAReply());
            stat.setNum_mentions(stat.getNum_mentions() + tweet.getMentions());
            stat.setNum_reTweets_recieved(stat.getNum_reTweets_recieved() + tweet.getReTweets());
            stat.setNum_hashTag(stat.getNum_hashTag() + tweet.getHashTags());
            stat.setNum_Urls(stat.getNum_Urls() + tweet.getUrls());
            stat.AddSources(tweet.getSource());
            stat.AddUrls(tweet.getURLS());

            if (tweet.isASimpleTweet() == 1) {
                //if it's a imple tweet find the tweets tha are similar to this.
                if (list == null) {
                    list = new ArrayList<>();
                }

                list.clear();
                findDublicates(tweet, user.getID(), count2);
            }
            count2++;

        }
        userTweets.close();

        stat.setSameTweets(dublist);

        BasicDBObject dbObject = stat.getDBObject2();
        dbAdapter.getInstance().insertUserStats(dbObject);

        this.writeRow(fileName, 1, lastrow++, stat.getExelRow());

    }
    users.close();
}