Scheme rewriting of MongoDB configuration weights

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.