1

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?

2
  • Why downvote? There is something wrong? Commented Mar 15, 2017 at 9:25
  • I think column data type should be json. In your case information column should be data type of json. Commented Mar 15, 2017 at 9:33

1 Answer 1

1

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}

Sign up to request clarification or add additional context in comments.

1 Comment

That is worked for laravel (5.8.36) mongodb (4.0.14)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.