✎
编程开发网
首页
C语言
C++
面试
Linux
函数
Windows
数据库
下载
搜索
当前位置:
首页
->
AI编程基础
->
数据库编程
MongoDB数据读写的几种方法(二)
2014-11-24 03:24:03
·
作者:
·
浏览:
7
标签:
MongoDB
数据
读写
方法
使用时需要调用get方法生成具体query语句 ArrayList
articles = new ArrayList
(); //此处element类型均为Object HashSet
clusters = new HashSet
(); DBObject article = null; while(curs.hasNext()) { article = curs.next(); articles.add(article.get("_id")); clusters.add(article.get("clusterId")); } QueryBuilder removeBuilder = new QueryBuilder(); //注意下句使用了$in操作符,类似于{_id: articleID1} or {_id: articleID2} or {_id: articleID3} ... DBObject removeObject = new BasicDBObject("_id", new BasicDBObject("$in", articles)); removeBuilder.and(removeObject); /*打印结果*/ coll.remove(removeBuilder.get()); DBObject articleCountQuery = null; for(Object o: clusters) { articleCountQuery = new BasicDBObject("clusterId", o); curs = coll.find(articleCountQuery); if(curs.count() != 0) { clusters.remove(o); } } removeObject = new BasicDBObject("clusterId", new BasicDBObject("$in", clusters)); removeBuilder.and(removeObject); coll.remove(removeBuilder.get()); /** curs = coll.find(removeBuilder.get()); articles = new ArrayList
(); clusters = new HashSet
(); article = null; while(curs.hasNext()) { article = curs.next(); articles.add(article.get("_id")); clusters.add(article.get("clusterId")); } /**/ System.out.println(articles); System.out.println(clusters); } }
定时操作,参考这篇博文,利用Java代码
编程
实现(利用开源库Quartz)。
Linux
的环境可以使用crontab工具,更为简单方便。此处所需要配合使用的JS代码简略。
首页
上一页
1
2
下一页
尾页
2
/2/2