1

I'm new to MongoDB. Just wondering:

How do I convert this shell command to ruby?

db.unicorns.find(null, {name: 1, _id:0});

This gives me an error:

db.collection("unicorns").find(nil, :fields=>["name","_id"=>0])

If you have any tutorial resources as well, would appreciate :).

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Mr. Demetrius Michael
  • 2,326
  • 5
  • 28
  • 40

1 Answers1

4

That should almost work. The error you're getting is something like this:

TypeError: keys must be strings or symbols

right? Just use a Hash for fields instead of an Array:

db.collection("unicorns").find(nil, :fields => { :name => true, :_id => false })

So it is pretty much a straight transliteration of the JavaScript version.

Sorry, I don't know of any tutorials on this stuff let alone good ones. I've figured it out myself through guess work and extrapolating the JavaScript docs.

Community
  • 1
  • 1
mu is too short
  • 426,620
  • 70
  • 833
  • 800