Loading ...
Sorry, an error occurred while loading the content.

Problem with find combining has terms

Expand Messages
  • stephanfopeano
    Hi, I seem to be having a problem with the find method. I m combining terms using the has operator, and expected them to be AND d, but they seem to be
    Message 1 of 3 , Apr 16, 2010
    • 0 Attachment
      Hi,

      I seem to be having a problem with the find method. I'm combining terms using the has operator, and expected them to be AND'd, but they seem to be returning OR results:

      academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}

      I would expect this to find both 93 and 115 in the "academic" array, but it returns an array with records with either 93 or 115. Am I doing something wrong?

      Thanks,

      Stephan
    • tacoman_cool
      Stephan, Actually you re looking at a feature of JavaScript. Since an object {} can contain only one of any given key any duplicates are ignored. So
      Message 2 of 3 , Apr 16, 2010
      • 0 Attachment
        Stephan,

        Actually you're looking at a feature of JavaScript. Since an object {} can contain only one of any given key any duplicates are ignored.

        So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}})

        Is really something like:

        So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}})

        Since either the first or second academic value will be ignored.

        To do what you want you'll need to use the subfilter feature of find:

        So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}},collection.find({academic:{"has":"115"}}))

        Here the results of the first find attempt ({academic:{"has":"115"}}) are passed into the second find attempt which then filters only those results. The end result is academic must have both 115 and 93 to be returned.

        Ian

        --- In taffydb@yahoogroups.com, "stephanfopeano" <stephan.fopeano@...> wrote:
        >
        > Hi,
        >
        > I seem to be having a problem with the find method. I'm combining terms using the has operator, and expected them to be AND'd, but they seem to be returning OR results:
        >
        > academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}
        >
        > I would expect this to find both 93 and 115 in the "academic" array, but it returns an array with records with either 93 or 115. Am I doing something wrong?
        >
        > Thanks,
        >
        >
        >
      • stephanfopeano
        Thanks, Ian. That explains it! Thanks for the great tool! -Stephan
        Message 3 of 3 , Apr 16, 2010
        • 0 Attachment
          Thanks, Ian. That explains it! Thanks for the great tool!

          -Stephan

          --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
          >
          > Stephan,
          >
          > Actually you're looking at a feature of JavaScript. Since an object {} can contain only one of any given key any duplicates are ignored.
          >
          > So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}})
          >
          > Is really something like:
          >
          > So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}})
          >
          > Since either the first or second academic value will be ignored.
          >
          > To do what you want you'll need to use the subfilter feature of find:
          >
          > So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}},collection.find({academic:{"has":"115"}}))
          >
          > Here the results of the first find attempt ({academic:{"has":"115"}}) are passed into the second find attempt which then filters only those results. The end result is academic must have both 115 and 93 to be returned.
          >
          > Ian
          >
          > --- In taffydb@yahoogroups.com, "stephanfopeano" <stephan.fopeano@> wrote:
          > >
          > > Hi,
          > >
          > > I seem to be having a problem with the find method. I'm combining terms using the has operator, and expected them to be AND'd, but they seem to be returning OR results:
          > >
          > > academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}
          > >
          > > I would expect this to find both 93 and 115 in the "academic" array, but it returns an array with records with either 93 or 115. Am I doing something wrong?
          > >
          > > Thanks,
          > >
          > >
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.