0
votes

I want to use lookup to take some data from a collection and put it in another collection.

Does not matter what i write in localfield or foreignfield, because takes all the data from player_game_stats and insert it in every document in player collection. I want to check if localfield and foreignField are equal, but lookup does not check this. I use NoSqlBooster for mongodb

db.player.aggregate().lookup({
      from:'player_game_stats',
      localField: 'player.id',
      foreignField: 'player_game_stats.player_id',
      as: "games"
})
1
Please post some sample collection and the output - Ashh

1 Answers

0
votes

Verify from your database if the id field needs an underscore, if it does, then the localfield should be '_id' but if it is not then 'id' will be fine

db.player.aggregate().lookup({
  from:'player_game_stats',
  localField: 'id',
  foreignField: 'player_id',
  as: "games"
 })