PHP MongoDB Upsert无效

时间:2014-04-15 17:24:57

标签: php mongodb

这是我的代码:

  public function insertJob($search = array(), $doc) {
    echo(print_r($doc));
    echo("\n");
    $this->collection->update(
        $search,
        array('$set' => (array)$doc),
        array('upsert' => true)
      );
  }

$search以这种方式设置:

$ft = new FastTrackMongo($arg);

$api = new JobsAPI('API_KEY_HERE');

foreach ($industries as $industry) {
  $jobs = $api->getJobs($industry);
  echo("CALLING API FOR " . $industry . "\n");
  foreach($jobs->job as $job) {
    echo("INSERTING " . $job->title . "\n");

    $job->address = $job->location;
    unset($job->location);

    $date = DateTime::createFromFormat('Y-n-d h:i A', $job->dateacquired);
    $date = $date->format('Y-m-d H:i:s');

    $job->dateacquired = $date;
    $job->industry = $industry;
    $ft->insertJob(array('jvid' => $job->jvid, 'industry' => $industry), $job);
  }
}

由于某种原因,upsert'ing无效。该脚本不断转储新记录。

0 个答案:

没有答案