【问题标题】:MongoDB PHP using $in with arrayMongoDB PHP 使用 $in 和数组
【发布时间】:2012-03-30 21:15:34
【问题描述】:

我正在使用 MongoDB 和 PHP,并尝试根据生成的数组执行 $in。

当我手动指定相同的数组时,它可以工作,但是当我构建它时,它会返回具有相同数据的任何结果。

这就是我所拥有的:

$settings = array();
foreach($items as $item) {
   $settings[] = $item['id'];
}

//Settings is the same as this
$setting2 = array(1,2,3,4,5,6,7,8);

//This returns no results
$cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $settings)));


//This does return results
$cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $setting2)));

我已经检查过使用

$cursor->info()

而且数组中的项都是一样的。

任何想法我做错了什么?

谢谢!

【问题讨论】:

    标签: php mongodb mongodb-php


    【解决方案1】:

    数字的数据类型可能不一样。尝试在构建的数组和指定的数组上使用 var_dump() 。您可能会看到一个将它们作为字符串中的数字,而另一个将它们作为简单的整数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多