【问题标题】:How can I use JSON Where Clauses on laravel mongodb? (Laravel 5.3)如何在 laravel mongodb 上使用 JSON Where 子句? (Laravel 5.3)
【发布时间】:2017-08-05 22:41:31
【问题描述】:

我在 mongodb compass 上的数据是这样的:

我从这里读到:https://laravel.com/docs/5.3/queries#json-where-clauses

我尝试实现这样的 json where 子句:

Message::where('information->seller_id', 1)
       ->get();

结果未显示。而数据存在

这个查询似乎仍然错误

我尝试在这里阅读参考:https://github.com/jenssegers/laravel-mongodb

但是我没找到

我该如何解决这个问题?

【问题讨论】:

  • 为什么要投反对票?有什么问题吗?
  • 我认为列数据类型应该是json。在您的情况下,information 列应该是 json 的数据类型。

标签: php json mongodb laravel laravel-5.3


【解决方案1】:

要从 JSON 中选择数据,请使用 . 而不是 ->

Message::where('information.seller_id', 1)
       ->get();

另外,您的数据当前是string,您需要它是JSON。只需删除它周围的引号:

information : {"store_id":6,"some_other_data":"123", "seller_id":1}

【讨论】:

  • 适用于 laravel (5.8.36) mongodb (4.0.14)
猜你喜欢
  • 2017-11-30
  • 2021-11-13
  • 1970-01-01
  • 2020-09-18
  • 2017-01-03
  • 1970-01-01
  • 1970-01-01
  • 2017-02-17
  • 2019-09-08
相关资源
最近更新 更多