miaozy лет назад: 4
Родитель
Сommit
083722aa39

+ 0 - 11
ipu-mongodb-example/src/test/java/com/ai/ipu/example/mongodb/MongodbExample.java

208
  }
208
  }
209

209

210
  /**
210
  /**
211
   * 查询符合条件的所有数据(分页)
212
   *
213
   * @throws Exception
214
   */
215
  public void testExecuteSelectByPage() throws Exception {
216
    JSONObject cond = new JSONObject();
217
    cond.put("nickName", "tom");
218
    log.debug("查询结果为:" + noSql.executeSelect(cond.toJSONString()));
219
  }
220

221
  /**
222
   * 设置返回记录的最大条数,查询符合条件的数据。
211
   * 设置返回记录的最大条数,查询符合条件的数据。
223
   * 类似mysql的limit
212
   * 类似mysql的limit
224
   * 类似oracle的rownum
213
   * 类似oracle的rownum

+ 10 - 1
ipu-mongodb-example/src/test/java/com/ai/ipu/example/mongodb/MongodbExampleWithSql.java

69
    noSql.executeUpdate("update mycol1 set remarks = '2' where name = 'test'");
69
    noSql.executeUpdate("update mycol1 set remarks = '2' where name = 'test'");
70
  }
70
  }
71
71
72
73
  /**
74
   * 使用标准SQL条件查询mongodb(分页)
75
   * @throws Exception
76
   */
77
  public void testExecuteSelect1() throws Exception {
78
    log.debug("查询结果为:" + noSql.executeSelect("select * from mycol1 limit 0,5"));
79
  }
80
72
  /**
81
  /**
73
   * 使用标准SQL,where条件查询mongodb
82
   * 使用标准SQL,where条件查询mongodb
74
   * 简单的汇总计数
83
   * 简单的汇总计数
135
   * 分类汇总
144
   * 分类汇总
136
   * @throws Exception
145
   * @throws Exception
137
   */
146
   */
138
  public void testExecuteSelect1() throws Exception {
147
  public void testExecuteSelect8() throws Exception {
139
    log.debug("查询结果为:" + noSql.executeSelect("select name,nickName,sum(age) sumAge,count(1) totalNum from mycol1 where name != 'mike' group by name,nickName  having sumAge>=10 order by sumAge desc"));
148
    log.debug("查询结果为:" + noSql.executeSelect("select name,nickName,sum(age) sumAge,count(1) totalNum from mycol1 where name != 'mike' group by name,nickName  having sumAge>=10 order by sumAge desc"));
140
  }
149
  }
141
}
150
}