Modify the primary key type of MongoDB, record

Source: Internet
Author: User

Because the preliminary design is not week-long, the primary key _ id is objectid, so it is not convenient to update and maintain. It is too troublesome to modify it later.

// A duplicate record will be created. "city" and "category" are the unique indexes in the collection.
DB. categorycount. Find ({"_ id": {"$ type": 7}). foreach (function (x ){

X. _ id = "" + X. City + X. category;
DB. categorycount. Save (X );
});

// Through the above call, you have copied a record. The primary key is not of the string type. The record whose old objectid is the primary key will be deleted below
DB. categorycount. Remove ({"_ id": {"$ type": 7 }});

// The type value corresponding to the type is

Type Value
Double 1
String 2
Object 3
Array 4
Binary data 5
Object ID 7
Boolean 8
Date 9
Null 10
Regular Expression 11
JavaScript code 13
Symbol 14
JavaScript code with scope 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min key 255 *
Max key 127
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.