Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

_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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants