Skip to content

Instantly share code, notes, and snippets.

@nmerouze
Created February 19, 2010 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmerouze/308914 to your computer and use it in GitHub Desktop.
Save nmerouze/308914 to your computer and use it in GitHub Desktop.
import com.mongodb.Mongo
import com.mongodb.DBCollection
import com.mongodb.BasicDBObject
import com.mongodb.DBObject
import com.mongodb.DBCursor
import com.mongodb.DB
import java.util.Set
import java.util.List
begin
m = Mongo.new
db = m.getDB "mydb"
# the rest of the code will go here
rescue Exception
end
colls = db.getCollectionNames
colls.each do |coll|
puts coll
end
testColl = db.getCollection "testCollection"
testColl.drop # drop the data from previous test
doc = BasicDBObject.new
doc.put "name", "MongoDB"
doc.put "type", "database"
doc.put "count", 1
info = BasicDBObject.new
info.put "x", 203
info.put "y", 102
doc.put "info", info
testColl.insert(doc)
myDoc = testColl.findOne
puts myDoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment