LoginSignup
0
0

More than 3 years have passed since last update.

Google Datastore 1500bytes制限と回避方法(PHP)

Posted at

概要

Google Datatstoreは、型定義もテーブル定義もせずがんがんデータ突っ込めます。
が、デフォルトのままデータ入れていると、1500バイトを超えたところで、PHPの場合、500エラーで止まります。
エラーメッセージは、The value of property "data" is longer than 1500 bytes という感じ。

なぜエラーが出るか、大きなデータは突っ込めないのか。

Datastoreは、何も指定しなければ、インデックスが貼られます。
インデックスが貼られているデータは、1500バイトまでという制限があります。
つまり、インデックスを貼らなければOK

データ挿入時にインデックス対象から外す

事前のテーブル定義がないので、データ挿入時にインデックスしない、という指定をするしかなさそう。

コード

PHPのライブラリでデータをINSERTするときのコード。
以下のコードの場合、answerdetailだけインデックスしません。

$dbKey = $datastore->key($GLOBALS['DB_prefix'].'groupexamlog');
$dbData = $datastore->entity(
    $dbKey,
    [
        'groupid' => $groupid,
        'userid' => $userid,
        'score' => $score,
        'scoremax' => $scoremax,
        'duration' => $duration,
        'answertime' => $answertime,
        'answerdetail' => $answerdetail
    ],[
        'excludeFromIndexes' => ['answerdetail']
    ]
);
$result = $datastore->insert($dbData);

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0