Created
August 3, 2012 22:04
-
-
Save fearofcode/3251976 to your computer and use it in GitHub Desktop.
simple example of using $addToSet + $each operator with Java driver from scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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