$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()
]);
当我使用moloquent推送数据时如何更改mongodb中的键值
当我推送时,mongodb总是会生成增量密钥,我该如何更改?
答案 0 :(得分:0)
您必须覆盖_id因为MongoDB总是为您的bson生成默认ID,或者如果您想要禁用它,您可以创建没有默认索引的收藏
db.createCollection("coll", { autoIndexId: false })
这可以在mongo控制台中完成