How to insert multiple documents at once in MongoDB through Java

DBCollection.insert accepts a parameter of type DBObject, List<DBObject> or an array of DBObjects for inserting multiple documents at once. You are passing in a string array. You must manually populate documents(DBObjects), insert them to a List<DBObject> or an array of DBObjects and eventually insert them. DBObject document1 = new BasicDBObject(); document1.put(“name”, “Kiran”); document1.put(“age”, 20); DBObject … Read more

Bulk Insert records into Active Record table

Use the activerecord-import gem. Let us say you are reading a CSV file and generating a Product catalogue and you want to insert records in batches of 1000: batch,batch_size = [], 1_000 CSV.foreach(“/data/new_products.csv”, :headers => true) do |row| batch << Product.new(row) if batch.size >= batch_size Product.import batch batch = [] end end Product.import batch

Bulk Insertion on Android device

Normally, each time db.insert() is used, SQLite creates a transaction (and resulting journal file in the filesystem), which slows things down. If you use db.beginTransaction() and db.endTransaction() SQLite creates only a single journal file on the filesystem and then commits all the inserts at the same time, dramatically speeding things up. Here is some pseudo … Read more

BULK INSERT with identity (auto-increment) column

Add an id column to the csv file and leave it blank: id,Name,Address ,name1,addr test 1 ,name2,addr test 2 Remove KEEPIDENTITY keyword from query: BULK INSERT Employee FROM ‘path\tempFile.csv ‘ WITH (FIRSTROW = 2,FIELDTERMINATOR = ‘,’ , ROWTERMINATOR = ‘\n’); The id identity field will be auto-incremented. If you assign values to the id field … Read more