Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Created January 4, 2019 02:56
Show Gist options
  • Select an option

  • Save jvmvik/bce1ca199bf967109a1209b37ef85fd5 to your computer and use it in GitHub Desktop.

Select an option

Save jvmvik/bce1ca199bf967109a1209b37ef85fd5 to your computer and use it in GitHub Desktop.
Show basic usage of mongoDB ruby driver
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