4

所以我有以下工匠命令控制器:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use MongoDB;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'testcommand';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
        $bulk = new MongoDB\Driver\BulkWrite();
        $bulk->insert(['test', 'data']);
        $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
        $manager->executeBulkWrite('test.test', $bulk, $writeConcern);
    }
}

当我尝试使用php artisan testcommand(它在 Kernel.php 中定义)运行它时,我收到以下错误:

  [MongoDB\Driver\Exception\BulkWriteException]
  BulkWrite error

这是非常无用的通用性。知道问题是什么吗?

4

0 回答 0