Hi, trying to retrieve contents of a client database through Ruby’s mongo documentation, however when outputting my collections via puts db and db[:collection name], the console returns an object of the form
#<Mongo::Database:0x000000010e726190>
or
#<Mongo::Collection:0x0000000109c63b30>
and not actual explicit values and its parameters. Does anyone know how to solve this?
While this doesn’t answer your question, I noticed that the link you provided is to an older version (2.2) of the driver. Are you following along with that, are you using the most recent version’s (2.18) documentation?
As you mentioned, I am trying to retrieve documents within my database. However, upon calling the find function on my DB collection, I am still unable to see the relevant document output.
Below is my code snippet:
The output which I was expecting to receive was this:
_id
"10006546"
listing_url
"https://www.airbnb.com/rooms/10006546"
name
"Ribeira Charming Duplex"
summary
"Fantastic duplex apartment with three bedrooms, located in the histori…"
space
"Privileged views of the Douro River and Ribeira square, our apartment …"
description
"Fantastic duplex apartment with three bedrooms, located in the histori…"
However i keep getting nil values.
The Database has been made public and hence you would be able to access it as well through mongoDB compass through the URI in my code snippet.
To get your desired output you need to iterate the result, for example:
# Print the first result
puts collection.find({name: "Ribeira Charming Duplex"}).first
# Print all results
collection.find({name: "Ribeira Charming Duplex"}).each do |document|
puts document
end
Please remove the open access to your cluster. If you want to provide help for reproducing an issue, a sample document and the specific versions of software used should be a great starting point.