0

次の形式のドキュメントがあります。

[uuid] => d030b8d1
[commentstrings] => Array (
    [0] => 1366220389#mac@test.org#test 1
    [1] => 1366220422#mac@test.org#test 2
    [2] => 1366220458#mac@test.org#test 3
)

コメント文字列の 1 つの完全な文字列があり、その値を削除したいと考えています。

CLIでこれを試してみると、うまくいきます:

 db.messages.update(
     {'uuid':'d030b8d1'}, 
     { $pull : {
         'commentstrings': '1366220422#mac@test.org#test 2'
     }} 
 )

しかし、PHP で同じことを試しても何も起こりません。

$response = $stdb->messages->update(
    array('uuid'=>'d030b8d1'),
    array('$pull' => array('commentstrings' => '1366220422#mac@test.org#test 2'))
);

ここで私が間違っていることは何ですか?

4

4 に答える 4

1

私はこの動作を取得しません:

$mongodb->ghghghg->insert(array('uuid' => 'd030b8d1',
        'commentstrings' => Array (
            '1366220389#mac@test.org#test 1',
            '1366220422#mac@test.org#test 2',
            '1366220458#mac@test.org#test 3'
)));

var_dump($mongodb->ghghghg->findOne());

$response = $mongodb->ghghghg->update(
        array('uuid'=>'d030b8d1'),
        array('$pull' => array('commentstrings' => '1366220422#mac@test.org#test 2'))
);

var_dump($mongodb->ghghghg->findOne());

版画:

array
  '_id' => 
    object(MongoId)[19]
      public '$id' => string '516ffff96803fa2261000000' (length=24)
  'uuid' => string 'd030b8d1' (length=8)
  'commentstrings' => 
    array
      0 => string '1366220389#mac@test.org#test 1' (length=30)
      1 => string '1366220422#mac@test.org#test 2' (length=30)
      2 => string '1366220458#mac@test.org#test 3' (length=30)

array
  '_id' => 
    object(MongoId)[18]
      public '$id' => string '516ffff96803fa2261000000' (length=24)
  'commentstrings' => 
    array
      0 => string '1366220389#mac@test.org#test 1' (length=30)
      1 => string '1366220458#mac@test.org#test 3' (length=30)
  'uuid' => string 'd030b8d1' (length=8)

使用しているドライバーのバージョンと PHP のバージョンを教えてください。

commentstringsまた、それが配列であると確信していますか? PHP ではなく、MongoDB コンソールを見て、どのように出力されるかを確認してください。

于 2013-04-18T14:16:41.037 に答える
0

試す

$data = array('$pull' => array('commentstrings' => '1366220422#mac@test.org#test 2'));
$response = $stdb->messages->update(array('uuid'=>'d030b8d1'), $data);
var_dump($response);

何を返しますか?

于 2013-04-18T13:56:01.333 に答える
0

私のコードが正しかったことがわかりました。変数のタイプミスでした。

于 2013-04-18T14:57:25.823 に答える
0

これを試して

$response = $stdb->messages->update(array('uuid'=>'d030b8d1'),array('$pull' => array('commentstrings' => '1366220422\#mac\@test.org\#test 2')));
于 2013-04-18T13:50:33.920 に答える