我正在尝试对使用 Spring 数据定义的对象列表执行批量插入
@Document(collection="feeds")
public class Feed {
@Id
private String id;
@Field (value="feed_url")
private String feedUrl;
@Field (value="last_read")
private Date lastRead;
private String image;
private int status;
private int retry;
...
运行以下代码时我没有收到任何错误,但我的集合中只插入了一个文档。
ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml");
MongoOperations mongoOperations = (MongoOperations) ctx.getBean("mongoTemplate");
List<Feed> feeds = new LinkedList<Feed>();
for(int i=0; i<10; i++){
feeds.add(new Feed("http://myweb.com/"+i));
}
mongoOperations.insert(feeds, Feed.class);
如何在一次操作中插入多个文档?