Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created August 3, 2012 22:04
Show Gist options
  • Save fearofcode/3251976 to your computer and use it in GitHub Desktop.
Save fearofcode/3251976 to your computer and use it in GitHub Desktop.
simple example of using $addToSet + $each operator with Java driver from scala
package com.stackmob.mongoaddtoset
import com.mongodb._
import org.bson.types.ObjectId
object MongoAddToSet extends App {
val conn = new Mongo("localhost", 27017)
val db = conn.getDB("addtoset")
val items = db.getCollection("items")
val addToSet = new BasicDBObject("$addToSet", new BasicDBObject("value", new BasicDBObject("$each", Array(1,2,3,4, 5, 6))))
items.update(new BasicDBObject("_id", new ObjectId("501c2824484ff81318b5643a")), addToSet)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment