Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query returns only id not the fields specified. #294

Closed
ccovey opened this issue Apr 9, 2016 · 6 comments
Closed

Query returns only id not the fields specified. #294

ccovey opened this issue Apr 9, 2016 · 6 comments
Labels

Comments

@ccovey
Copy link

ccovey commented Apr 9, 2016

We have the following query.

$lovesArray = $this->getLovesCollection()
     ->findOne(
           ['_id' => new \MongoId($loves->getId())],
           ['loveItems' => ['$elemMatch' => ['sellable.$id' => new \MongoId($sellable->getId())]]]
      );

Using mongdb (and the mongo-php-adapter) I get the following array back.

array:1 [
  "_id" => MongoId {#17769
    -objectID: MongoDB\BSON\ObjectID {#17287}
  }
]

But with the old driver I receive the data as expected.

array:2 [
  "_id" => MongoId {#16617
    +$id: "570873273ec93556800041b7"
  }
  "loveItems" => array:1 [
    0 => array:4 [
      "_id" => MongoId {#16619
        +$id: "570873273ec93556800041be"
      }
      "sellable" => array:3 [
        "$ref" => "sellables"
        "$id" => MongoId {#16571
          +$id: "570873273ec93556800041b8"
        }
        "$db" => "opensky_devo_test"
      ]
      "createdAt" => MongoDate {#17015
        +sec: 1460171559
        +usec: 876000
      }
      "status" => "manually_added"
    ]
  ]
]

Also of note, I'm not 100% sure if this is a driver bug or a bug in the adapter. If this is not from the driver just let me know I'll close and move to the adapter repo.

@ccovey ccovey changed the title Query returns only id not the fields specified. Only happens on 5.5 not 5.6 Query returns only id not the fields specified. Apr 9, 2016
@jmikola
Copy link
Member

jmikola commented Apr 12, 2016

We have a number of tests for query projections in the driver, so I'd defer to @alcaeus to confirm whether this a bug in mongo-php-adapter. If possible, I'm sure he'd appreciate it if you could turn this into a PHPUnit test case.

@alcaeus
Copy link
Member

alcaeus commented Apr 13, 2016

Thanks for bringing this to my attention, @jmikola. I've confirmed the issue exists and I'm trying to figure out whether it's due to a bug in mongo-php-adapter or somewhere else. I'll update here and in the linked ticket once I know more.

@alcaeus
Copy link
Member

alcaeus commented Apr 13, 2016

Update: this is indeed a bug with mongo-php-adapter, being fixed in alcaeus/mongo-php-adapter#98. The error occurs when using BSON types in query projections, which were not properly converted to the new types.

@alcaeus
Copy link
Member

alcaeus commented Apr 13, 2016

Last update: 1.0.3 of mongo-php-adapter containing a fix was released.

@ccovey
Copy link
Author

ccovey commented Apr 13, 2016

I'm sure @alcaeus hates me at this point but thanks a ton for your hard work!

@jmikola
Copy link
Member

jmikola commented Apr 14, 2016

Thanks, @alcaeus! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants