簡體   English   中英

Doctrine 和 Mongodb:刪除所有字段不在數組中的文檔

[英]Doctrine and Mongodb: Remove all documents with field not in array

我想刪除所有字段不在我擁有的 id 數組中的文檔。 當我嘗試時,它只會從我的數據庫中刪除所有內容。

這是我的代碼:

public function removeNotInListingIdList($ids, $country) {
      $dm = $this->getDocumentManager();
      $dm->createQueryBuilder('DnDReactivePandoraBundle:Property')
        ->remove()
        ->field('listingId')->notIn($ids)
        ->field('country', $country)
        ->getQuery()
        ->execute();
  }

我在這里做錯了什么?

更新

這是調試指令的輸出:

Array
(
    [type] => 3
    [query] => Array
        (
            [listingId] => Array
                (
                    [$nin] => Array
                        (
                            [0] => 15-77
                            [1] => 15-79
                            [2] => 15-82
                            [3] => 13-39
                            [4] => 15-85
                            [5] => 15-86
                            [6] => 15-60
                            [7] => 15-61
                            [8] => 16-8
                        )

                )

            [country] => Mexico
        )

    [newObj] => Array
        (
        )

)

你的領域國家沒有正確構建。 應該是:

   $dm = $this->getDocumentManager();
   $dm->createQueryBuilder('DnDReactivePandoraBundle:Property')
      ->remove()
      ->field('listingId')->notIn($ids)
      ->field('country')->equals($country)
      ->getQuery()
      ->execute();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM