{
"price": [
{
"availability": {
"available_dow": [
"1",
"2",
"3",
"4",
"5",
"6"
]
},
},
{
"availability": {
"available_dow": [
"0"
]
},
}
],
}[$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] =>
)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.
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
[$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.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:
php -i | grep -i mongo (assuming you are using a UNIX-like O/S)Best regards,
Kevin
$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 -i | grep -i mongo
/etc/php.d/mongo.ini,mongoMongoDB Support => enabledMONGODB-CR => enabledMONGODB-X509 => enabledmongo.allow_empty_keys => 0 => 0mongo.chunk_size => 261120 => 261120mongo.cmd => $ => $mongo.default_host => localhost => localhostmongo.default_port => 27017 => 27017mongo.is_master_interval => 15 => 15mongo.long_as_object => 0 => 0mongo.native_long => 1 => 1mongo.ping_interval => 5 => 5Hi,
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