Java操作Mongo bulkWrite批量入库

Mongo bulkWrite示例

public boolean insertBulk(String collectionName, JSONArray array) {MongoCollection<Document> collection = db.getCollection(collectionName);List<InsertOneModel<Document>> documentList = array.stream().map(item -> {Document document = Document.parse(((JSONObject)item).toJSONString());document.put("_id", document.getString("id"));return new InsertOneModel<Document>(document);}).collect(Collectors.toList());ListUtils.partition(documentList,1000).forEach(item->{collection.bulkWrite(item);});return true;
}

ListUtils.partition来自于

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.3</version>
</dependency>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416643.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

工作总结17:组件封装思想

就是把部门下拉框选择这部分变成一个组件&#xff0c;在用户创建的时候引入这样就可以把功能不相关代码模块化&#xff0c;以后也便于管理如果别的地方也要用到部门选择&#xff0c;可以直接再次引入&#xff0c;就不用重复写代码了

c#程序中使用quot;like“查询access数据库查询为空的问题

今天&#xff0c;在开发的过程中发现了一个特别奇怪的问题&#xff1a;access中like查询时候。在Access数据库中运行&#xff0c;发现能够查询出结果。这是在数据库上运行。select * from KPProj where KpName like *測试*&#xff0c;可是相同的语句在c#程序中却查询为空。这是…

SpringBoot启动yaml报错

报错找不到org.yaml里的一个方法 10:45:54.742 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getScalarStyle()Lorg/yaml/snakeyaml/DumperOptions$ScalarStyle;at …

JS中的预编译(词法分析)阶段和执行阶段

javascript相对于其它语言来说是一种弱类型的语言&#xff0c;在其它如java语言中&#xff0c;程序的执行需要有编译的阶段&#xff0c;而在javascript中也有类似的“预编译阶段”&#xff08;javascript的预编译是以代码块为范围<script></script>&#xff0c;即每…

Excel分组最大级别为8(outlineLevel最大为7)

excel分组最大级别为8&#xff0c;超过则会删除。 事故现场 Java操作POI分组超过7级&#xff08;算上末级节点&#xff0c;一共8级&#xff09;&#xff0c; 分组作用在sheetData节点下row节点的outlineLevel上&#xff0c;一级分组没有该属性&#xff0c;2-8级分组该值对应为…

Java 的Tuple(类似.net等的元组)

commons-lang3包 两个参数&#xff1a;MutablePair&#xff08;可修改&#xff09;、ImmutablePair&#xff0c;三个参数&#xff1a;MutableTriple&#xff08;可修改&#xff09;、ImmutableTriple&#xff08;不可修改&#xff09; 包commons-lang3 3.8.1里就有 org/apach…

day02-java关键字

转载于:https://www.cnblogs.com/tantanba/p/6917959.html

JacksonUtils Jackson的JSON序列化反序列化

pom.xml添加依赖 <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.11.3</version> </dependency>公共方法 import com.fasterxml.jackson.core.JsonProces…

工作总结8:关于Vue中的slot-scope=“scope“

<template><el-table :data"tableData" style"width: 100%">//---:data"用于存放请求数据回来的数组"<el-table-column label"索引值" width"400"><template slot-scope"scope">//--- 这…

文本

文本样式&#xff1a; color       设置字体颜色 text-align    元素水平对齐方式 text-indent   首行文本的缩进 "em"或"px" line-height    文本的行高 text-decoration 文本的装饰  对齐方式&#xff1a; 水平对齐方式&#xff1a; t…

maven打包报错You have to use a classifier to attach supplemental artifacts to the project instead of rep

maven打包报错You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. [WARNING]JAR will be empty - no content was marked for inclusion!15:51:40 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-ja…

第一次绩效评估

评估结果如下&#xff1a; 第一名&#xff1a;谢梦雨 第二名&#xff1a;田会 第三名&#xff1a;王凤彬 第四名&#xff1a;张贺转载于:https://www.cnblogs.com/xtwz/p/7025874.html

前端学习(2439):jsonbin-init的使用

const str {"id":1253585734669959168} console.log(JSONbig.parse(str)) console.log(JSON.parse(str).id.toString()) const data JSON.stringify(str) console.log(JSONbig.parse(data)) console.log(JSONbig.stringify(data))

OpenJDK8基础类库包清单

包中文描述英文描述java.applet提供创建小程序所需的类&#xff0c;以及小程序用于与其小程序上下文进行通信的类。Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context.java.awt包含用于创建用户界面…

《C#高级编程》笔记系列第三弹

我们在开发WinForm时&#xff0c;经常会看到partial关键字&#xff0c;比如&#xff0c;我们新建一个Windows Form时&#xff0c;后台代码自动添加如下&#xff1a; 1 public partial class Form1 : Form2 {3 public Form1()4 {5 InitializeComponent();6 …

linux下node-sass安装失败

报错 Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-72_binding.node Cannot download “https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-72_binding.node”: 原因 v4.11.0版本没有linux-x64-7…

Hadoop生态系统学习路线

主要介绍Hadoop家族产品&#xff0c;经常使用的项目包含Hadoop, Hive, Pig, HBase, Sqoop, Mahout, Zookeeper, Avro, Ambari, Chukwa。新添加的项目包含&#xff0c;YARN, Hcatalog, Oozie, Cassandra, Hama, Whirr, Flume, Bigtop, Crunch, Hue等。从2011年開始。中国进入大数…

前端学习(2440):axios处理文章数据

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…