I want to configure a weight pool, have 3 weights a,b,c, choose 2 IDs according to different weights
My original design was
Weight A:[id1,id2 ...]
Weight B:[id1,id2 ...]
Weight C:[id1,id2 ...]
The operations of the weights are $push, $pop, and take the entire table operation, so that if frequent operations are likely to cause the marked
One of my colleagues suggested another option:
{
{
Uid:id1
Weight:a
}
{
Uid:id2
Weight:b
}
......
}
Just add the weight key to the index and fetch all the a documents according to the weight index.
The following advantages are as follows:
Directly with $set can change the weight, (with Pop,push) pop a value will traverse the array, the data volume is large, inefficient, and even may lead to lock table.
Weight the index, the speed of the full ID of the a weight is 2/3 faster than the index (indexed, which is the direct lookup).
Scheme rewriting of MongoDB configuration weights