CRUD using the Ruby driver
The Ruby driver was originally maintained by an external community member who was later hired by MongoDB. Subsequently, Ruby became one of the first languages to receive official support from MongoDB with an official driver.
MongoDB Ruby driver includes an integrated query cache. Once activated, this cache retains outcomes from previous find and aggregation operations. When those queries are executed again, the driver serves the cached results, eliminating redundant database interactions. An example of using the query cache can be found later in this chapter, in the Mongoid ODM section.
The recommended method for connecting to a MongoDB instance with Ruby is through the official MongoDB Ruby driver on GitHub.
Connecting to a database
Add mongo
to your Gemfile
, as follows:
gem "mongo"
To install the driver manually, execute the following command:
gem install mongo
Then, in your class, you can connect to a database, as shown...