Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:04:37+00:00 2026-05-28T05:04:37+00:00

This is a newbie question. I find the method definition in the YARD Rdoc:

  • 0

This is a newbie question. I find the method definition in the YARD Rdoc:

(Object) find(selector = {}, opts = {})


Options Hash (opts):
:fields (Array, Hash) 

then I try this coll.find(‘English’ => ‘fulcrum’,{English:1,Chinese:1}), want the result ‘English’ field is fulcrum ,and only return English and Chinese field, but Ruby punished me with the this

irb(main):018:0> coll.find('English' => 'fulcrum',{English:1,Chinese:1})
SyntaxError: (irb):18: syntax error, unexpected ')', expecting tASSOC
    from /usr/local/bin/irb:12:in `<main>'
irb(main):019:0> 

I want to know why, thanks

after correct the syntax problem by the suggestion by @mu, I got Unknown options error:

irb(main):013:0> coll.find({English:'fulcrum'},{English:1, :Chinese => 1})RuntimeError: Unknown options [{:English=>1, :Chinese=>1}]
    from /usr/local/lib/ruby/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/collection.rb:234:in `find'
    from (irb):13
    from /usr/local/bin/irb:12:in `<main>'
irb(main):014:0> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:04:37+00:00Added an answer on May 28, 2026 at 5:04 am

    When Ruby sees an unwrapped Hash in argument list:

    o.m(k => v, ...)
    

    it assumes that you really mean this:

    o.m({ k => v, ... })
    

    So, when you say this:

    coll.find('English' => 'fulcrum', {English: 1, Chinese: 1})
    

    Ruby sees this:

    coll.find({ 'English' => 'fulcrum', {English: 1, Chinese: 1} })
    

    A Hash is a perfectly valid key so Ruby expects it to be followed by a => value:

    coll.find('English' => 'fulcrum', {English: 1, Chinese: 1} => some_value)
    

    and that’s where the error message comes from:

    syntax error, unexpected ')', expecting tASSOC
    

    If you want to pass two hashes, you need to wrap the first one in braces:

    coll.find({'English' => 'fulcrum'}, {English: 1, Chinese: 1})
    

    The second argument to [find](
    http://api.mongodb.org/ruby/current/Mongo/Collection.html#find-instance_method) should be an options Hash and it looks like you want the :fields option and you can give that an array of names instead of a noisy Hash:

    coll.find({'English' => 'fulcrum'}, :fields => %w[English Chinese])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a very newbie question, but I didn't find anything satisfying I
This is a newbie question but I cant seem to find to do the
Maybe this is a newbie question or RTFM question... but I couldn't find it
This is a kind of newbie question, but I couldn't find a solution. I
Sorry if this is a newbie question. I can't seem to find a response
this is a bit of a newbie question but I can't seem to find
I'm sure this is a newbie question, but every time I've compiled/dl'ed a new
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I'm really new to VSTO so sorry if this is a newbie question. I'm
Total newbie question but this is driving me mad! I'm trying this: myInt =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.