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

_id: null #51

Closed
kdauzickas opened this issue Oct 31, 2012 · 10 comments
Closed

_id: null #51

kdauzickas opened this issue Oct 31, 2012 · 10 comments
Labels

Comments

@kdauzickas
Copy link

Genghis fails to handle objects that have null for id, e.g. {_id: null}

@bobthecow
Copy link
Owner

Hmm. That's interesting... Why do you have an object like that? :)

@kdauzickas
Copy link
Author

I created it accidentally. A bug nonetheless :)

@bobthecow
Copy link
Owner

Well, that was dumb. Thanks for reporting it. I'll try to figure out a way to save you from yourself ;)

@kdauzickas
Copy link
Author

php also spews out notices about array to string conversion when the id is an array (yup, an array). There is ambiguity in this case. Mongo documentation states: The _id value can be of any type with type ObjectId being the most common. It also states: The _id value may be of any type, other than arrays, so long as it is a unique. And the actual db ignores the last statement allowing to save objects with array ids.

@bobthecow
Copy link
Owner

Two things on the array id:

  1. You're not using an array id. You're using a hash ID :)

  2. What you're seeing is a failure of the PHP Mongo driver. The "array" representation of a cursor — what you get when you do iterator_to_array — uses the document IDs as the array index. You can imagine how much that would mess things up if you tried to do something like this:

    $foo[array('some' => 'value')] = $document;
    

    It works most of the time because ObjectId instances __toString as a hex string of their ID. But you'll see the exact same error if you try to cast whatever your id value is into a string.

    I don't know if the bug has been reported yet, but you can check the 10gen JIRA tickets if you want. I'll try to find a workaround for Genghis, though, because unfortunately the PHP driver doesn't have the fastest bug fix turnaround at this point.

@bobthecow
Copy link
Owner

Here's where it all fails:

@bobthecow
Copy link
Owner

Okay. The null ID is fixed in de558c9 ... it'll go out in the next release :)

@bobthecow
Copy link
Owner

I fixed a couple more issues for when you use dumb IDs like null, these fixes will be in the next release as well :)

@jmikola
Copy link

jmikola commented Nov 13, 2012

@bobthecow: Thanks for pinging me on this. I created PHP-570 to track the issue.

@bobthecow
Copy link
Owner

@jmikola Thanks for reporting it via the proper channel :)

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