MongoDB常用语法

1 MongoVUE用法

1.1 模糊查询

头匹配:

  {"title":new RegExp("^各地发起纪念周总理")}

任意位置匹配:

  {"published":{$gte: "2013-05-01", $lt: "2013-06-10"}, "title":new RegExp(".*北京.*")}

1.2 时间段查询

{"published":{$gte: "2013-05-01", $lt: "2013-06-10"}}

1.3 联合查询

{"published":{$gte: "2013-05-01", $lt: "2013-06-10"}, "title":new RegExp("^北京")}

1.4 特定域查询

  find:   {"user.screen_name":"_juliannemoore","retweeted_status":null,

"in_reply_to_status_id_str":null,"text":new RegExp(".*@.*")}

  fields: {"_id":false, "text":true}

2 mongo.jar用法

2.1 联合查询

BasicDBObject query = new BasicDBObject();

query.put("published", new BasicDBObject("$gte", "2013-05-01").append("$lt", "2013-06-11"));

query.put("title", new BasicDBObject("$regex", ".*北京.*"));

2.2 Array特定域Update

DBObject query = new BasicDBObject();

query.put("id", Long.parseLong("510842471837097985"));

query.put("entities.user_mentions.screen_name", "liyakebede");

DBObject update = new BasicDBObject();

update.put("$set", new BasicDBObject("entities.user_mentions.$.link_type","friend"));

WriteResult result = col.update(query, update);

 

 

 

你可能感兴趣的:(mongodb)