MongoDB数据查询

{
  "_id" : ObjectId("5382a76b723497651a3d49ef"),
  "name" :"世界杯",
  "comments" : [{
      "id" : "20140610001",
      "name" : "不错"
    }, {
      "id" : "20140610002",
      "name" : "巴西"
    }],
   "status":1
}

   查询状态==1,评论数=2,且评论中内容是“巴西”的记录

    

{"status":1,"comments":{"$elemMatch":{"name":"巴西"},"$size":2}}
		List<String> country = new ArrayList<String>();
		diseases.add("巴西");
		diseases.add("中国");
		BasicDBObject query = new BasicDBObject();
		query.put("comments.name", new BasicDBObject("$in", country));

  $ne, $lte, $gte, $lt, $gt,$exists,$in,$nin,$all,$or,$size,$slice,$mod,$not,$elemMatch,还有正则

猜你喜欢

转载自itace.iteye.com/blog/2082224