We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

zero-length keys are not allowed -> Problem retreiving value when int64 is zero in mongodb

I am using mongodb and the collections manager.

I have a collection that has an int in it:

    /**
     *
     * @var int
     */
    public $invoice_count;

In mongo db I have manually set invoice_count(Int64) to 0(zero).

When I try and access $company->invoice_count after:

    $company = CompanyInvoices::findFirst(array(
        array("company_id" => $company->id)
    ));

Then I get:

    zero-length keys are not allowed, did you use $ with double quotes?

Why? Everything is ok if in mongodb invoice_count(Int64) is set to 1. When its zero then if falls over....

Is this a bug?



34.6k
Accepted
answer

Do you have an empty field name in your document? This problem is not related to the value



47.7k
edited Jul '15

Do you mean have I left out any fields before saving?

When I query the collection in robomongo the document in question has all the keys there and values of zero or an assigned value.

Do you have an empty field name in your document? This problem is not related to the value