i dont know if it's the same problem i got with pymonog, but because
you're dealing with nested documents, then you must add the dollar
sign
On 26 sep, 23:28, Smiffy <
smiffyt...@gmail.com> wrote:
> Hi Folks
>
> I am using the MongoDB-0.46.2 CPAN module, and am having problems querying
> for specific fields.
>
> I have the following data:
>
> {
> "_id" : ObjectId("50637b8017f354712f000000"),
> "phleem" : {
> "nox" : "nix",
> "ni" : "noo"
> },
> "foo" : {
> "bar" : NumberLong(123),
> "baz" : NumberLong(456)
> }
>
> }
>
> If I perform the following query from the shell, I get the
> desired/anticipated result:
>
> > db.test.findOne({ 'foo.bar' : 123}, { 'foo.baz' : 1, 'phleem.nox' : 1 })
>
> {
> "_id" : ObjectId("50637b8017f354712f000000"),
> "phleem" : {
> "nox" : "nix"
> },
> "foo" : {
> "baz" : NumberLong(456)
> }
>
> }
>
> However, here's what happens when I try to do what I think is the same query
> from Perl:
>
> print Dumper(
> $c->find(
> { 'foo.bar' => 123},
> { 'foo.baz' => 1, 'phleem.nox' => 1 }
> )->all
> );
>
> ...which gives me:
>
> $VAR1 = {
> 'phleem' => {
> 'ni' => 'noo',
> 'nox' => 'nix'
> },
> '_id' => bless( {
> 'value' => '50637b8017f354712f000000'
> }, 'MongoDB::OID' ),
> 'foo' => {
> 'bar' => 123,
> 'baz' => 456
> }
>
> };
>
> I used the "SELECT a,b FROM users WHERE age=33" example from here:
http://search.cpan.org/~friedo/MongoDB-0.46.2/lib/MongoDB/Examples.pod
>
> Why am I getting the full document, rather than just the specified fields?
>
> Cheers
>
> M