MongoDB的学习一
这里的内容是我在使用MongoDB中经常用到的内容,在这里总结出来。加深印象,也为了以后不断进步提高。
- 根据日期查询MongoDB中的记录
Document document = new Document();
document.put("queryDate",Date);
MongoCollection<Document> collection = getDefaultDB().getCollection("mongoCollectionName");
MongoCursor<Document> mongoCursor = collection.find(document).projection(new Document("cache",true).append("ids",true)).iterator();
#find()参数为Bson格式的,过滤条件
#projection()参数也为Bson,但是是保留哪个属性(列)
#append()是追加内容不仅可以用在projection()中也可以用到find()中。