Created
January 4, 2019 02:56
-
-
Save jvmvik/bce1ca199bf967109a1209b37ef85fd5 to your computer and use it in GitHub Desktop.
Show basic usage of mongoDB ruby driver
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
| require 'mongo' | |
| client = Mongo::Client.new("mongodb://localhost:27017", {database: 'test'}) | |
| db = client.db | |
| # Show all collection | |
| db.collection_names | |
| # Count number of document | |
| db["searches"].count() | |
| # Find one document | |
| db["searches"].find({}, {limit: 1}).first | |
| # Find one document and show all keys | |
| db["searches"].find({}, {limit: 1}).first.keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment