rahmat vanario
rahmat vanario

Reputation: 13

reference id with mongodb by laravel jenssegers

i have two models, i need to get model A data that have reference in model B by array id, this is my model A object

 { 
    "_id": "62eb2f788345c04a74057903",
   "location": "usa"
 }

and this is my model B

 {
     "_id": "62eb2f788345c04a74057903",
     "name": "task",
     "desc": "test task",
     "location_id ":["62eb2f788345c04a74057903", "62eb2f788345c04a74057904"]
 }

how can i get model data A from model data B query by jenssegers library? is there any other solutions for this case? i've try use hasMany and belongToMany but the result is null,

Upvotes: 0

Views: 1109

Answers (1)

rahmat vanario
rahmat vanario

Reputation: 13

solve this using raw query mongo, [how to use lookup with jenssegers] [1]: https://github.com/jenssegers/laravel-mongodb/issues/841#issuecomment-260106920

this is mongo db doc about lookup [how to use lookup with mongo] [2]: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#std-label-unwind-example

Upvotes: 0

Related Questions