作者:起五贪黑_719 | 来源:互联网 | 2023-09-13 14:27
Hello,
I have a document like this. I'm trying to update
and increment
by one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| {
"_id" : ObjectId("5ba0f8155cb8512fee57d538"),
"customer_id" : 53,
"code" : "PYDY15",
"data" : {
"assign_total" : 1,
"usage_total" : 0,
"usage" : [
{
"order_id" : null,
"state" : "Active",
"time" : ISODate("2018-09-18T13:05:25.058Z")
}
]
},
"updated_at" : ISODate("2018-09-18T15:37:51.000Z"),
"created_at" : ISODate("2018-09-18T13:05:25.000Z")
} |
When I execute the following code WITHOUT
part it works and updates the
1 2 3 4 5 6 7 8 9 10
| CouponUsage::query()
->where('customer_id', $customer->customer_id)
->where('code', $coupon->code)
->where('data.usage.state', 'Active')
->update([
'data.usage.$.order_id' => $order->order_id,
//'$inc' => [
//'data.usage_total' => 1
//]
]); |
But if I enable the
section, it gives the following error:
1
| The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage. |
How can I update and increment the values?
该提问来源于开源项目:jenssegers/laravel-mongodb
Thank you so much! it worked!