The dotted field 'X.X.X' in 'X.X.X' is not valid for storage.

2,064 views
Skip to first unread message

migsy

unread,
Jun 1, 2016, 4:43:18 AM6/1/16
to mongodb-user
Hello everyone

I have the following document:

{
 
"price": [
   
{
     
"availability": {
       
"available_dow": [
         
"1",
         
"2",
         
"3",
         
"4",
         
"5",
         
"6"
       
]
     
},
   
},
   
{
     
"availability": {
       
"available_dow": [
         
"0"
       
]
     
},
   
}
 
],
}

And I am trying to $set the following code:

[$set] => Array
 
(
     
[price.0.availability.unavailable_dates] => Array
         
(
             
[0] => MongoDate Object
                 
(
                     
[sec] => 1464739200
                     
[usec] => 0
                 
)


         
)


     
[price.0.availability.available_dow] => Array
         
(
             
[0] => 2
             
[1] => 3
             
[2] => 4
             
[3] => 5
             
[4] => 6
         
)


     
[price.0.availability.available_dates] =>
     
[price.1.availability.unavailable_dates] =>
     
[price.1.availability.available_dow] => Array
         
(
             
[0] => 0
         
)


     
[price.1.availability.available_dates] =>
 
)


And I am getting the following error:

Update of data into MongoDB failed: xxxxxxxx: The dotted field 'price.0.availability.unavailable_dates' in 'price.0.availability.unavailable_dates' is not valid for storage.

As far as I understand from reading the documentation, if a field does not exist (in this case, 'price.0.availability.unavailable_dates') it is created. Therefore, I don't understand the error I am getting.

Anybody could please help me?

Many thanks in advance.

migsy

unread,
Jun 1, 2016, 4:49:40 AM6/1/16
to mongodb-user
Perhaps it's worth noting that I'm using version 2.6.

Regards.

migsy

unread,
Jun 5, 2016, 1:25:59 PM6/5/16
to mongodb-user
Hi

Could anybody please give me a hint? I am completely stuck.

Thanks very much.

Kevin Adistambha

unread,
Jun 9, 2016, 12:16:25 AM6/9/16
to mongodb-user

Hi,

Update of data into MongoDB failed: xxxxxxxx: The dotted field 'price.0.availability.unavailable_dates' in 'price.0.availability.unavailable_dates' is not valid for storage.

As far as I understand from reading the documentation, if a field does not exist (in this case, ‘price.0.availability.unavailable_dates’) it is created. Therefore, I don’t understand the error I am getting.

From the code you posted, I believe you are using PHP. The issue is that you have an invalid PHP array notation in your code. Using your example data, this code seems to work as intended (using PHP 5.6.22 and MongoDB PHP Driver 1.1.7):

require 'vendor/autoload.php';

// Connect to test database
$db = (new MongoDB\Client)->test;

// Update statement
date_default_timezone_set('Etc/UCT');
$update = array(
    '$set' => array(
        'price.0.availability.unavailable_dates' => new MongoDate(strtotime("2016-01-01 00:00:00")),
        'price.0.availability.available_dow' => array('2', '3', '4', '5', '6')
    )
);

// Perform update
$db->test->updateOne(array(), $update);

Also please note that MongoDB 2.6 will be reaching its end-of-life on October 2016. If your use case permits, I would recommend you to upgrade to the latest MongoDB (currently at version 3.2.7) for major improvements and bugfixes.

Best regards,
Kevin

migsy

unread,
Jun 9, 2016, 6:01:04 AM6/9/16
to mongodb-user
Hi Kevin

Thank you very much for your response.

Sorry, I forgot to mention that I was using PHP (5.3.3 in fact).

I tested your exact code, and I got the same error, so I am beginning to think that is a problem with the mongo driver and/or database version. Do you agree? I haven't updated the database and driver in case the existing code didn't work.

[$set] => Array
       
(
           
[price.0.availability.unavailable_dates] => MongoDate Object
               
(
                   
[sec] => 1451606400
                   
[usec] => 0

               
)


           
[price.0.availability.available_dow] => Array
               
(
                   
[0] => 2
                   
[1] => 3
                   
[2] => 4
                   
[3] => 5
                   
[4] => 6
               
)



       
)






Update of data into MongoDB failed: The dotted field 'price.0.availability.unavailable_dates' in 'price.0.availability.unavailable_dates' is not valid for storage.

Regards.

Kevin Adistambha

unread,
Jun 9, 2016, 11:16:11 PM6/9/16
to mongodb-user

Hi,

I tested your exact code, and I got the same error, so I am beginning to think that is a problem with the mongo driver and/or database version. Do you agree? I haven’t updated the database and driver in case the existing code didn’t work.

Could you post:

  • the PHP code that you tried
  • the PHP driver version you are using
  • the output of php -i | grep -i mongo (assuming you are using a UNIX-like O/S)

Best regards,
Kevin

migsy

unread,
Jun 10, 2016, 4:54:18 AM6/10/16
to mongodb-user
Hi Kevin

Thanks again for your response.

Below you can find all the info you asked.

$id is an exisiting item in the database.

$cmd = array(
   '$set' => array(
       'price.0.availability.unavailable_dates' => new MongoDate(strtotime("2016-01-01 00:00:00")),
       'price.0.availability.available_dow' => array('2', '3', '4', '5', '6')
   )
);
$result = $this->db->{$collection}->update(array('_id' => $id), $cmd, array('upsert' => $upsert, 'w' => 1));

PHP driver version: 1.6.14
PHP version: 5.4.45
OS: Centos 6.8
Mongodb version: 2.6

php -i | grep -i mongo

/etc/php.d/mongo.ini,
mongo
MongoDB Support => enabled
MONGODB-CR => enabled
MONGODB-X509 => enabled
mongo.allow_empty_keys => 0 => 0
mongo.chunk_size => 261120 => 261120
mongo.cmd => $ => $
mongo.default_host => localhost => localhost
mongo.default_port => 27017 => 27017
mongo.is_master_interval => 15 => 15
mongo.long_as_object => 0 => 0
mongo.native_long => 1 => 1
mongo.ping_interval => 5 => 5


Thank you very much.

migsy

unread,
Jun 15, 2016, 5:57:12 AM6/15/16
to mongodb-user
Hi Kevin

Have you had a chance to look at this?

Many thanks in advance!

Kevin Adistambha

unread,
Jun 17, 2016, 12:26:09 AM6/17/16
to mongodb-user

Hi,

I’m afraid I cannot reproduce the exact error you are seeing. This is the complete code that I used. I’m trying to mimic your intent as closely as possible:

<?php
date_default_timezone_set('Etc/UCT');

class TestMongoUpdate {
    function TestMongoUpdate() {
        $this->db = (new MongoClient("mongodb://localhost/"))->test;
    }
    function set() {
        $collection = 'test';
        $upsert = True;
        $cmd = array(
                    '$set' => array(
                        'price.0.availability.unavailable_dates' => new MongoDate(strtotime("2016-01-01 00:00:00")),
                        'price.0.availability.available_dow' => array('2', '3', '4', '5', '6')
                    )
                );
        $result = $this->db->{$collection}->update(array(), $cmd, array('upsert' => $upsert, 'w' => 1));
        var_dump($result);
    }
};

$testmongo = new TestMongoUpdate();
$testmongo->set();
?>

Have you tried the code with an empty collection and see if the error still persist?

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages