import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
/** *
用java 往mongoDB插入数据 * @author wwd
* */
public class InsertData {
public static void main(String[]args) throws UnknownHostException{
Mongo mongo=new Mongo("127.0.0.1",27017);//链接mongoDB
DB db=mongo.getDB("test");//获取test数据库
DBCollection collection=db.getCollection("user");//获取user集合
//向user集合插入一条数据
DBObject object=new BasicDBObject();
object.put("name", "李四");
object.put("age",23);
collection.insert(object);
}
}