I am trying to get a subset of fields from MongoDB with a query made in Ruby, but it does not work. It does not return any results.
This is the ruby ββcode:
coll.find("title" => 'Halo', :fields => ["title", "isrc"]) #this doesn't work
If I delete field hashes, it works by returning results with all fields
coll.find("title" => 'Halo') #this works
Looking at the mongodb console, the first request ends on the mongodb server as follows:
{ title: "Halo", fields: [ "title", "isrc" ] }
If I try to make a request from the mongo client console, it works, I get the results and a subset. I am making a request as follows:
db.tracks.find({title: 'Halo'}, {title:1,isrc:1})
What could be the problem? I have been looking for a solution for this for several hours.
ruby mongodb subset
Nick dima
source share