【发布时间】:2013-04-16 09:01:54
【问题描述】:
有没有办法将所有项目集合复制到新集合而不循环所有项目? 我找到了一种通过 DBCursor 循环的方法:
...
DB db = mongoTemplate.getDb();
DBCursor cursor = db.getCollection("xxx").find();
//loop all items in collection
while (cursor.hasNext()) {
BasicDBObject b = (BasicDBObject) cursor.next();
// copy to new collection
service.createNewCollection(b);
}
...
您能否建议在不循环所有项目的情况下在 java 中进行复制?
(不在 mongo shell 中,使用 java 实现)
Tnx。
【问题讨论】:
-
您使用的是哪个版本的 Mongo?如果 2.1 可以帮助你 -> stackoverflow.com/questions/8933307/… - 特别是接受答案下方的评论。
-
这是 mongo shell,我需要 java 实现
-
你的问题是这样的“你能建议在不循环所有项目的情况下进行复制吗?(在 mongo shell 中,使用 java 实现)Tnx。”。你不能在 mongo shell 中使用 java。
-
你知道用java怎么做吗?
-
没有,但是阅读文档让我理解了它的工作原理。你读过吗?
标签: java mongodb collections