Created
February 19, 2010 17:06
-
-
Save nmerouze/308914 to your computer and use it in GitHub Desktop.
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
| 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 |
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
| begin | |
| m = Mongo.new | |
| db = m.getDB "mydb" | |
| # the rest of the code will go here | |
| rescue Exception | |
| end |
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
| colls = db.getCollectionNames | |
| colls.each do |coll| | |
| puts coll | |
| end |
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
| testColl = db.getCollection "testCollection" | |
| testColl.drop # drop the data from previous test |
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
| 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 |
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
| testColl.insert(doc) |
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
| myDoc = testColl.findOne | |
| puts myDoc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment