当我用moloquent推送数据时,如何更改mongodb中的键值

时间:2017-09-16 16:25:22

标签: mongodb laravel moloquent

$cart = Cart::where('user_id', $request->user_id)->push('cart', [ 
    "uuid" => uniqid(), 
    "product_id" => $request->product_id, 
    "product_type_id" => $request->product_type_id, 
    "address_id" => $request->address_id, 
    "voucher_id" => $request->voucher_id, 
    "coureer_id" => $request->coureer_id, 
    "note" => $request->note, 
    "qty" => $request->qty, 
    "type" => $request->type, 
    "expired_at" => $this->addWeekFromCurrentTime(4), 
    "created_at" => $this->getCurrentTime() 
]);

this is the result

当我使用moloquent推送数据时如何更改mongodb中的键值

当我推送时,mongodb总是会生成增量密钥,我该如何更改?

1 个答案:

答案 0 :(得分:0)

您必须覆盖_id因为MongoDB总是为您的bson生成默认ID,或者如果您想要禁用它,您可以创建没有默认索引的收藏

db.createCollection("coll", { autoIndexId: false }) 

这可以在mongo控制台中完成