如何使用spark和mongo Hadoop连接器更新mongo集合中的多个字段?

时间:2014-12-22 12:20:53

标签: mongodb scala hadoop apache-spark

我正在使用mongo hadoop连接器将mongo连接到spark和scala。

我想使用mongo和spark更新(upsert)mongo集合的多个值。

我试过跟随 -

val query = new BasicBSONObject()
query.append("customerId", customerId)

val update = new BasicBSONObject()
val bson = new BasicBSONObject()
bson.put("minimumUtilization", some value)
bson.put("maximumUtilization", some value)
bson.put("averageUtilization", some value)
bson.put("customerId", customerId)

现在如何使用spark和mongo hadoop连接器使用上面的对象来更新集合?

1 个答案:

答案 0 :(得分:0)

见这里:https://github.com/mongodb/mongo-hadoop/wiki/Spark-Usage

使用MongoUpdateWritable。 创建一个MongoUpdateWritable的RDD(查询,更新,upsert,multiupdate,replace)然后

import { Directive, Input } from '@angular/core';
import { TemplateRef, ViewContainerRef } from '@angular/core';
@Directive({ selector: '[myUnless]' })
export class UnlessDirective {
  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainer: ViewContainerRef
    ) { }
  @Input() set myUnless(condition: boolean) {
    if (!condition) {
      this.viewContainer.createEmbeddedView(this.templateRef);
    } else {
      this.viewContainer.clear();
    }
  }
}
相关问题