In the original: share my simple code to test the MONGODB database
Source code: Http://www.zuidaima.com/share/1550463424236544.htm
Distributed file storage System, MONGODB deployment installation can be referenced as follows:
Http://www.cnblogs.com/mecity/archive/2011/06/11/2078527.html
The demo enables the data to be read row by line from the TXT file and stored in the MongoDB database.
Refer to other demo codes
This is a simple case source based on spring, Hibernate, Spring Data, Akka, Twitter Bootstrap, Apache Tiles, jquery.
Http://www.zuidaima.com/share/1550463264246784.htm
Share Java operations with MongoDB's CRUD code
The code includes MongoDB's crud and its paging query, sorting function
Http://www.zuidaima.com/share/1550463230446592.htm
Package com.zuidaima.pb.test;/** * Time spent in testing the MONGODB database for queries (MS) * @author Zoe www.zuidaima.com * Date 2012-12-26 */import JAV A.io.bufferedreader;import Java.io.file;import Java.io.filereader;import Java.net.unknownhostexception;import Java.util.regex.pattern;import Com.mongodb.basicdbobject;import Com.mongodb.db;import com.mongodb.DBCollection; Import Com.mongodb.dbcursor;import Com.mongodb.mongo;public class Mymongodb {/* * get dbcollction * @return */public Stati C dbcollection Getcoll () {Mongo Mongo;try {Mongo = new Mongo ("localhost", 27017);D b DB = Mongo.getdb ("working");D Bcollecti On coll = db.getcollection ("mytest"); return coll;} catch (Unknownhostexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return null;} /* This method is to put the data in the TXT file into the MongoDB database row by line * and the data in each row is placed in only one field, if the data in a row is to be placed in more than one field, there is no validation */public static void Add () {String URL = "D:/file.txt"; try {FileReader read = new FileReader (new file (URL)); BufferedReader br = new BufferedReader (read); StringBuffer SBF = new StriNgbuffer (""); String line = Null;int i = 0;dbcollection coll = getcoll (), while (line = Br.readline ()) = null) {Coll.insert (new basicdb Object (). Append ("name", line). Append ("No", i++);} System.out.println (Coll.getcount ());} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}} /* * No index query */public static void query () {dbcollection coll=getcoll (); Basicdbobject cond = new Basicdbobject (); Pattern pattern = pattern.compile ("Zhejiang *$"), Long a = System.currenttimemillis (), Cond.put ("name", pattern);//Cond.put (" Name "," Ninghai Electronic Technology Co., Ltd. ");D bcursor returns = Coll.find (cond); int i = 0;while (Returns.hasnext () && (++i <)) {Sy Stem.out.println (Returns.next ());} Long B = System.currenttimemillis (); System.out.println ("Elapsed Time" + (B-A) + "millisecond");} public static void Main (string[] args) {query ();}}
Share the simple code that HA I tested the MongoDB database