Package com.mongodb

Examples of com.mongodb.DBCollection.find()


            }

            query.put("metricTimestamp", timestampQuery);
        }

        return collection.find(query)
                         .sort(new BasicDBObject("metricTimestamp", -1))
                         .skip((pageNum - 1) * pageSize)
                         .limit(pageSize)
                         .toArray();
    }
View Full Code Here


    public Iterable<Map<String, Object>> getDocumentsAsMap(String collectionName) {
        try {
            final DB db = getMongoDb();
            final DBCollection collection = db.getCollection(collectionName);

            final DBCursor allDocuments = collection.find();

            return new Iterable<Map<String, Object>>() {

                @Override
                public Iterator<Map<String, Object>> iterator() {
View Full Code Here

    }

    @Override
    public Iterator<StateReader> instancesOf(final String specificationName) {
        final DBCollection instances = db.getCollection(specificationName);
        final DBCursor cursor = instances.find();
        LOG.info("searching for instances of: " + specificationName);
        return new Iterator<StateReader>() {
            @Override
            public boolean hasNext() {
                return cursor.hasNext();
View Full Code Here

  @Override
  public void forEachTuple(Consumer consumer, EntityKeyMetadata... entityKeyMetadatas) {
    DB db = provider.getDatabase();
    for ( EntityKeyMetadata entityKeyMetadata : entityKeyMetadatas ) {
      DBCollection collection = db.getCollection( entityKeyMetadata.getTable() );
      for ( DBObject dbObject : collection.find() ) {
        consumer.consume( new Tuple( new MassIndexingMongoDBTupleSnapshot( dbObject, entityKeyMetadata ) ) );
      }
    }
  }
View Full Code Here

      validate( metadatas );
      collectionName = metadatas[0].getTable();
    }

    DBCollection collection = provider.getDatabase().getCollection( collectionName );
    DBCursor cursor = collection.find( mongodbQuery, projection );

    if ( orderBy != null ) {
      cursor.sort( orderBy );
    }
View Full Code Here

  @Override
  public void forEachTuple(Consumer consumer, EntityKeyMetadata... entityKeyMetadatas) {
    DB db = provider.getDatabase();
    for ( EntityKeyMetadata entityKeyMetadata : entityKeyMetadatas ) {
      DBCollection collection = db.getCollection( entityKeyMetadata.getTable() );
      for ( DBObject dbObject : collection.find() ) {
        consumer.consume( new Tuple( new MassIndexingMongoDBTupleSnapshot( dbObject, entityKeyMetadata ) ) );
      }
    }
  }
View Full Code Here

    DBCollection dbCollection = db.getCollection("testCollection");
    dbCollection.save(artist);
   
    DBObject query = new BasicDBObject();
    query.put("name", "John Coltrane");
    DBObject artistFromDB = dbCollection.find(query).next();
    Object albumFromDB = artistFromDB.get("album");
    if(albumFromDB instanceof Collection) {
      Object firstAlbumFromDB = ((Collection<?>) album).iterator().next();
      if(firstAlbumFromDB instanceof DBObject) {
        Object titleFromDB = album.get("title");
View Full Code Here

    final int BATCH_SIZE = 1000;
    BasicDBObject query = new BasicDBObject();
    if (null != newIdThreshold) {
      query.put("_id", new BasicDBObject(MongoDbManager.gt_, newIdThreshold));
    }
    DBCursor dbc = outputCollection.find(query).batchSize(BATCH_SIZE);
    Iterator<DBObject> it = dbc.iterator();
    ArrayList<DBObject> toEsList = new ArrayList<DBObject>(BATCH_SIZE);
    String jobtitle = new StringBuilder("custom:").append(job.jobtitle).toString();
    while (it.hasNext()) {
      DBObject dbo = it.next();
View Full Code Here

    // Optimize communityId into sourceKeys...
    if ((null != query.get(DocumentPojo.communityId_)) && (null == query.get(DocumentPojo.sourceKey_)))
    {
      try {
        ObjectId commId = query.getObjectId(DocumentPojo.communityId_);
        DBCursor dbc = sourcesDB.find(new BasicDBObject(SourcePojo.communityIds_, commId));
        String[] sourceKeys = new String[dbc.count()];
        int added = 0;
        for (DBObject dbo: dbc) {
          sourceKeys[added++] = (String) dbo.get(SourcePojo.key_);
        }
View Full Code Here

    }//TESTED all 3 cases
    //DEBUG
    //System.out.println("CHUNKQ=" + query.toString());
   
    // Get chunks and build queries
    DBCursor dbc = configDB.find(query);
    ArrayList<BasicDBObject> retList = new ArrayList<BasicDBObject>(dbc.count());
    while (dbc.hasNext()) {
      DBObject chunk = dbc.next();
      BasicDBObject derivedQuery = new BasicDBObject();
      BasicDBObject minObj = (BasicDBObject) chunk.get("min");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.