0

MongoDB と MongoDB PHP ドライバーを使用して、1 日ごとにグループ化する Twitter データのコレクションがあります。グループ化ごとに、サブフィールド データに基づいて 2 つのカウントを計算したいと思います。カウントの 1 つは、単に文字列の一致に基づいています (私はそれを理解しました)。もう 1 つは、配列に特定の文字列が含まれているかどうかを確認する必要があります。2 番目のテストを実行するコードはありますか?

group() パラメータについては、次のとおりです。

$initial = array(
  "count" => 0,
  "mentions" => 0
);

$reduce = new MongoCode(
  "
  function (doc, prev) { 
    if (doc.interaction.interaction.author.id == $twitter_id) {
      prev.count++; 
    }

    //Note, only returns true if first value in array is matched. How to return true if array contains value?
    if (doc.interaction.twitter.mention_ids == $twitter_id) {
       prev.mentions++;
    }
  }

");
4

1 に答える 1