moses toh
moses toh

Reputation: 13162

How can I use JSON Where Clauses on laravel mongodb? (Laravel 5.3)

My data on mongodb compass is like this :

enter image description here

I read from here : https://laravel.com/docs/5.3/queries#json-where-clauses

I try to implement json where clauses like this :

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

The results are not showing. Whereas the data exist

This query seems still wrong

I try read reference here : https://github.com/jenssegers/laravel-mongodb

But, I don't find it

How can I solve this problem?

Upvotes: 1

Views: 1451

Answers (1)

Hollings
Hollings

Reputation: 532

To select data from inside JSON, use a . instead of ->

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

Also, your data is currently a string, and you need it to be JSON. Just remove the quotes around it:

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

Upvotes: 1

Related Questions