According to the MongoDB official document:
The inequality operator $nin is not very selective since it often matches a large portion of the index. As a result, in many cases, a $nin query with an index may perform no better than a $nin query that must scan all documents in a collection.
It is not recommended to use
$nin operator in a production server because it will often do a full collection scan. But in my project, I have to query some results which does not contain some elements. So I started to optimize the performance.
When I was designing some general components in my website, there are some data to be read in redux store. With TypeScript, we can simply use connect and mapStateToProps like this:
In the mobile game Princess Connect Re:Dive, you can battle with other players in a 5v5 arena. In this arena, you only need to select your team with 5 units and the battle progress is fully automatic. So building a strong team is really important.
I'm building a function to generate a random team which based on the unit strength. Unit strength is easy to get because I have a database which record each match, and the unit strength should be the occurrence of one unit in all matches divided by the occurrence of all units. So the final question is, how can I choose a unit randomly by the unit strength?