MongoDB基础操作
最后更新:2024-05-10 05:30:01
|
状态:未完成
DataSet set = new DataSet(); Long fr = System.currentTimeMillis(); for(int i=0; i<10;i ++){ MongoDataRow row = new MongoDataRow(); row.put("_id", fr+i); row.put("name", "USER_"+i); row.put("code", "CODE"+i); row.put("age",i); set.add(row); } ConfigTable.DEFAULT_MONGO_ENTITY_CLASS = MongoDataRow.class; //insert时 _id不可以重复 //插入多行 long size = service.insert("crm_users",set); System.out.println("影响行数:"+size); //查询整个表 set = service.querys("crm_users"); //查部分列 主键_id默认查询 set = service.querys("crm_users(age,code)"); System.out.println("查询结果:"+set); //不查AGE和_id set = service.querys("crm_users(!age,!_id)"); //按条件查询 set = service.querys("crm_users", new DefaultConfigStore().and(Compare.GREAT,"age", 1) .and(Compare.LESS_EQUAL, "age", 5) .in("age", new Integer[]{1,2}) ,"name:%1%","code:%1"); System.out.println("查询结果:"+set); System.out.println("查询结果:"+set.size());