Sumit D
Sumit D

Reputation: 411

Updating Mongo doc in scala using cashbah

My sample doc in mongodb is:

{ "_id" : 3, "name" : "sachin", "profilepic" : "images/pics/3.jpg" }
{ "_id" : 1, "name" : "sumit", "profilepic" : "images/pics/2.jpg" }

I want to append status:0 to the doc whose name is "sachin". I am new to scala. I write the code

val query1=MongoDBObject("name"->"sachin")
val query= MongoDBObject(status->0)
coll.update(query1,query)

But it doesn't work..

Upvotes: 3

Views: 77

Answers (2)

Kris
Kris

Reputation: 5792

Simple googling will help here :). Here you have an example of finding the object:

coll.findOne(MongoDBObject("title" -> "Star Wars"))

and updating the object using its id:

coll.update(pfid, $set("year" -> 1994))

Full example you can find here: http://janxspirit.blogspot.com/2011/11/introduction-to-casbah-scala-mongodb.html

I'm sure you can find fully working examples on github, just clone, run and play with it.

Upvotes: 0

Prashant Thorat
Prashant Thorat

Reputation: 1812

Try this It worked fine for me

coll.update(query1,$set("status"->0)) 

Where query1 is your search query

Upvotes: 1

Related Questions