com.mongodb.client.model.Updates.pullByFilter()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.mongodb.client.model.Updates.pullByFilter()方法的一些代码示例,展示了Updates.pullByFilter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Updates.pullByFilter()方法的具体详情如下:
包路径:com.mongodb.client.model.Updates
类名称:Updates
方法名:pullByFilter

Updates.pullByFilter介绍

[英]Creates an update that removes from an array all elements that match the given filter.
[中]创建一个更新,从数组中删除与给定筛选器匹配的所有元素。

代码示例

代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common

@Test
public void testPullWithInPattern() {
  collection.insertOne(json("_id: 1, tags: ['aa', 'bb', 'ab', 'cc']"));
  collection.updateOne(json("_id: 1"), pullByFilter(in("tags", Pattern.compile("a+"))));
  assertThat(collection.find().first()).isEqualTo(json("_id: 1, tags: ['bb', 'cc']"));
}

代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common

@Test
public void testPullWithInPatternAnchored() {
  collection.insertOne(json("_id: 1, tags: ['aa', 'bb', 'ab', 'cc']"));
  collection.updateOne(json("_id: 1"), pullByFilter(in("tags", Pattern.compile("^a+$"))));
  assertThat(collection.find().first()).isEqualTo(json("_id: 1, tags: ['bb', 'ab', 'cc']"));
}

代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common

@Test
public void testPullWithInNumbers() {
  collection.insertOne(json("_id: 1, values: [1, 2, 2.5, 3.0, 4]"));
  collection.updateOne(json("_id: 1"), pullByFilter(in("values", Arrays.asList(2.0, 3, 4L))));
  assertThat(collection.find().first()).isEqualTo(json("_id: 1, values: [1, 2.5]"));
}

代码示例来源:origin: opencb/opencga

for (String gt : sc.getAttributes().getAsStringList(LOADED_GENOTYPES.key())) {
  updates.add(
      pullByFilter(
          in(DocumentToVariantConverter.STUDIES_FIELD + ".$." + GENOTYPES_FIELD + '.' + gt, sampleIds)));

相关文章