根据编程要求,完成在带有括号数字处的程序填空,在程序中实现对mongodb数据库CommentTest中comment集合,插入商品评论,包括用户在网站上注册的用户名称,评价内容,评价商品,评价时间,评价星级,评价标签等。并实现对其集合进行查询输出。 private MongoClient mongoClient; @Before public void initMongoClient()throws lOException mongoClient MongoDBUtil.(1); @Test(timeout 1000) public void saveCommentTest()throws lllegalArgumentException, IllegalAccessException Document document ConvertUtil.convertDoc(this.(2)); mongoClient.getDatabase("CommentTest").getCollection("comment") insertone((3)); @Test public void queryCommentTest(){ Findlterable<Document>iter =(4).getDatabase((5)) getCollection("comment").(6); iter.forEach(new Block<Document>(){ public void apply(Document doc){ System.out.printin(doc.toJson()); }方 @After public void closeMongoClient(){ mongoClient.(7); private Comment initComment(){ List<CommentLabel>commentLabels new ArrayList<CommentLabel>(); CommentLabel commentLabel1 new CommentLabel(): commentLabel1.setContent"品不i"): CommentLabel commentLabel2 new CommentLabel(); commentLabel2.setContent("非常耐用"); commentLabels.add(commentLabel1); commentLabels.add(commentLabel2); Comment comment new Comment(); comment.setCommentLabels(JsonUtil.toJson(commentLabels)); comment..setContent("快递非常快,下次还会买。"); comment.setCreatedTime(new Date()); comment.setPid(9000198); comment.setstar("4"); comment setUserName("admin): return (8);}}
时间: 2024-04-01 15:32:31 浏览: 124
在Docker中使用mongodb数据库的实现代码
填空如下:
1. new MongoClient()
2. initComment()
3. insertOne(document)
4. mongoClient.getDatabase("CommentTest").getCollection("comment").find()
5. CommentTest
6. find()
7. close()
8. comment
阅读全文