Exemplo n.º 1
0
  public void tweet(String body) {
    final ObjectId tweet_id = new ObjectId();
    final Date time = new Date();
    MongoCollection<Document> tweets = db.getCollection("tweets");
    MongoCollection<Document> userline = db.getCollection("userline");
    MongoCollection<Document> timeline = db.getCollection("timeline");
    MongoCollection<Document> followers = db.getCollection("followers");

    Document tweetDoc =
        new Document("tweet_id", tweet_id).append("username", nick).append("body", body);

    Document userDoc =
        new Document("username", nick).append("time", time).append("tweet_id", tweet_id);

    List<Document> timelineList = new ArrayList<>();
    List<Document> followerList =
        followers.find(eq("username", nick)).into(new ArrayList<Document>());
    for (Document doc : followerList) {
      String follower = (String) doc.get("follower");
      Document timeDoc =
          new Document("username", follower).append("time", time).append("tweet_id", tweet_id);
      timelineList.add(timeDoc);
    }

    tweets.insertOne(tweetDoc);
    userline.insertOne(userDoc);
    timeline.insertMany(timelineList);

    System.out.println("* You tweeted \"" + body + "\" at " + time);
  }
Exemplo n.º 2
0
      @FinishBundle
      public void finishBundle(Context ctx) throws Exception {
        MongoDatabase mongoDatabase = client.getDatabase(spec.database());
        MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(spec.collection());

        mongoCollection.insertMany(batch);

        batch.clear();
      }
Exemplo n.º 3
0
 @Override
 public void insertMany(List<? extends Document> arg0, InsertManyOptions arg1) {
   if (tx.started()) {
     tx.beforeInsertMany(coll, arg0);
     tx.getTxCollection().insertMany(arg0, arg1);
   } else {
     coll.insertMany(arg0, arg1);
   }
 }
  private static void importToMongoDB(
      String host, int port, String databaseName, String collectionName, List<Document> docList) {
    MongoClient client = new MongoClient(host, port);
    MongoDatabase database = client.getDatabase(databaseName);
    MongoCollection<Document> collection = database.getCollection(collectionName);

    collection.insertMany(docList);

    client.close();
  }
 public void insertVehicleEventLog(List<VehicleEventLog> vehicleEventLogs) {
   MessageParserServiceConfig config = new MessageParserServiceConfig();
   try (MongoClient mongoClient =
       new MongoClient(
           config.getConfig("mongo.db.host"), config.getConfigInt("mongo.db.port")); ) {
     MongoDatabase database = mongoClient.getDatabase("VehicleTrackingDB");
     MongoCollection<Document> collection = database.getCollection("VehicleEventLog");
     List<Document> documents = new ArrayList<Document>();
     for (VehicleEventLog vehicleEventLog : vehicleEventLogs) {
       documents.add(vehicleEventLog.toDocument());
     }
     collection.insertMany(documents);
     mongoClient.close();
   }
 }
Exemplo n.º 6
0
 public void saveDocuments(String collectionName, List<Document> documents) {
   MongoCollection<Document> mongoCollection = getCollectionByName(collectionName);
   mongoCollection.insertMany(documents);
 }
Exemplo n.º 7
0
 @Override
 public void insertMany(MongoCollection<Document> coll, List<Document> docs) {
   coll.insertMany(docs);
 }