mongodb for java使用中的小问题
1.批量更新老是忘掉后面的true
1 DBObject d = pCursor.next();
2 String id = d.get("id").toString();
3 Pattern p = Pattern.compile("^" + id,Pattern.CASE_INSENSITIVE);
4 BasicDBObject where = new BasicDBObject("id", p);
5 BasicDBObject field = new BasicDBObject("parentId", id);
6 BasicDBObject fields = new BasicDBObject("$set", field);
7 city.update(where, fields,false,<span style="color:#e53333;">true</span>);
2.去掉默认的_id
比较纠结,在客户端可以去掉查询结果的_id,但在java里怎么也去不掉
原来跟_id所在的位置有关系,如下:_id必须是field中的第一个key,如果_id跟code,name任意掉换下位置就过滤不掉了..
01 BasicDBObject where = new BasicDBObject("parentId", cityId);
02
03 BasicDBObject field = new BasicDBObject("_id", 0);
04
05 field.put("code", 1);
06
07 field.put("name", 1);
08
09
10 DBCursor cursor = weatherCode_coll.find(where, field);
作者 whxia320