在mongodb中,表(Table)被称之为集合(Collection),记录(Record)被称为文档(Document)
首先连接到数据库
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test"); 得到集合,这里取"text"
MongoCollection<Document> doc = db.getCollection("text"); 插入一个document
doc.insertOne(new Document("name","张三").append("age", 20)); 在执行insertOne方法的时候,如果database中不存在对应的名为"text"的集合,则自动创建这个collection,