0

I am using @grapecity/activereports-react in my react app. I am using my mongodb database as datasource. I created Server and endpoint to read my data from db ;

app.get('/:collectionName', async (req, res) => {
  try {
    const collectionName = req.params.collectionName;
    const collection = mongoose.connection.collection(collectionName);
    const data = await collection.aggregate([
      { $unwind: '$Statistics.Platforms' },
      { $unwind: '$Statistics.Weapons' },
      { $project: {
          _id: 1,
          'Run.Date': 1,
          'Run.Index': 1,
          'Run.Scenario.Name': 1,
          'Run.Scenario.Database': 1,
          'Run.Svn.Address': 1,
          'Run.Svn.Revision': 1,
          'Statistics.Platforms.Profile': 1,
          'Statistics.Platforms.Type': 1,
          'Statistics.Platforms.Force': 1,
          'Statistics.Platforms.Total': 1,
          'Statistics.Platforms.Wrecked': 1,
          'Statistics.Platforms.Destroyed': 1,
          'Statistics.Weapons.Profile':1,
          'Statistics.Weapons.Type' :1,
          'Statistics.Weapons.Force' :1,
          'Statistics.Weapons.Total' :1 ,
          'Statistics.Weapons.Hit' :1 ,
          'Statistics.Weapons.Missed' :1

        }
      },
    ]).toArray();
    res.json(data);
  } catch (err) {
    console.error(err);
    res.status(500).send('Server error');
  }
});

I want to unwind multiple arrays Statistics.Platforms and Statistics.Weapons. How can I do that ?

When I try the following code the output is wrong. In my database I have 21 Statistics.Platforms.Profile but with this code 42 Statistics.Platforms.Profile appears

{ $unwind: '$Statistics.Platforms' },
{ $unwind: '$Statistics.Weapons' },
user
  • 1
  • 3

0 Answers0