我正在使用mongo php库,并尝试将一些旧数据插入mongodb.我使用了insertMany()方法并传递了一大堆文档,这些文档可能在唯一索引上有重复的文档.
假设我有一个用户集合并拥有这些索引:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.users"
},
{
"v" : 1,
"unique" : true,
"key" : {
"email" : 1
},
"name" : "shop_id_1_title_1",
"ns" : "test.users"
}
]
Run Code Online (Sandbox Code Playgroud)
如果存在重复文档,MongoDB\Driver\Exception\BulkWriteException则会引发并停止该过程.我想找到一种方法来忽略插入重复文档(并防止引发异常)并继续插入其他文档.
我在php.net文档中找到了一个标志叫做continueOnError伎俩,但似乎它不能使用这个库.
来自php.net的例子:
<?php
$con = new Mongo;
$db = $con->demo;
$doc1 = array(
'_id' => new MongoId('4cb4ab6d7addf98506010001'),
'id' => 1,
'desc' => "ONE",
);
$doc2 …Run Code Online (Sandbox Code Playgroud) 您可能知道,命令总线已在laravel 5中实现.在laravel 5中有两种处理命令的方法.
这些方式的主要区别是什么?何时使用自我处理命令以及何时通过其相关命令处理程序处理命令?
对于简单的路线我知道我可以用户where声明.但是Route :: group()前缀中的参数如何呢?
<?php
Route::get('user/{id}', 'UserController@profile')->where('id', '[0-9]+');
Route::group(['prefix' => 'foo/{bar}'], function() {
// ...
})->where('bar', '[0-9a-Z]+'); // this won't work
Run Code Online (Sandbox Code Playgroud) 我正在使用 Lumen 5.5,并且编写了上传文件的简单应用程序。
我写了这样的测试(按照本教程)
<?php
class UploadImageTest extends TestCase
{
Use DatabaseMigrations;
public function testUploadingImageSuccessfully()
{
$this->json('POST', '/images', [
'image' => UploadedFile::fake()->image('image.jpg')
])->assertResponseOk()
}
}
Run Code Online (Sandbox Code Playgroud)
问题是在我的控制器中,$request->file('image')返回 null。
<?php
use Illuminate\Http\Request;
class UploadController extends Controller
{
public function upload(Request $request)
{
if ($request->file('image')) { // always return null
return "File is uploaded!";
}
return "File is not uploaded!";
}
}
Run Code Online (Sandbox Code Playgroud)
我检查了其他问题(例如这个问题)并尝试了给定的解决方案,但没有成功!