Getting a common BulkWrite error in MongoDB / Laravel

So, I have the following artisan command controller:

<?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);
    }
}

When I try to start it using php artisan testcommand(it is defined in Kernel.php), I get the following error:

  [MongoDB\Driver\Exception\BulkWriteException]
  BulkWrite error

It is very useless. Any idea what the problem is?

+4
source share

Source: https://habr.com/ru/post/1626722/


All Articles