MongoDB插入了一条不能正常工作的记录


MongoDB inserting a record not working as it should

所以,我已经为这段代码工作了一段时间,但我放弃了,并向你们寻求帮助。我一直在看MongoDB和PHP的文档,但什么都找不到。我想做的是获取插入记录的示例代码:

$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );

目的是为了我的项目(如图所示):

    $obj = array( $startCol => $startRow );

问题是$startCol和$startRow是数组,每次我想运行文档时都会遇到问题。我是不是错过了一些简单得离谱的东西?提前谢谢。

给我带来问题的代码块:

$maxRows= count($currentarray); //Outputs 45
$maxCols= count($currentarray[0]); //Outputs 9
$currentRow=1;
$currentCol=1;
$testing = 1;
    do {
    while ($currentCol<$maxCols){
        $startCol[] = $currentarray[0][$currentCol];
        $startRow[] = $currentarray[$currentRow][$currentCol];
        $currentCol++;
    }
    $obj = array( $startCol => $startRow );
    $collection->insert($obj);
    print_r ($collection);
    if ($currentCol==$maxCols)
    $currentCol=1;
    $currentRow++;
    $testing++;
    //echo "<br />";
    } while ($currentRow<$maxRows);

我遇到的问题是输出语句。所以我的回答相当简单。在print_r()之后,我发现我实际上存储了所有变量,但在程序结束时我错误地调用了它们。