- MongoDB Administrator’s Guide
- Cyrus Dasadia
- 300字
- 2021-07-02 15:47:48
How it works...
Most of the commands are pretty self-explanatory. In steps 1 and 2, we view and delete index respectively. You can also use db.<collection>.dropIndexes() to delete all indexes. In step 3, we recreate the index on the city field, but this time we provide an additional parameter to customize the name of the index. This can be confirmed by viewing the output of the getIndexes() command, as shown in step 3. Next, in step 4, we try to create another index on the city field (in ascending order). However, as we already have an index on this field, this would be redundant and hence MongoDB does not allow it. If you change the 1 to -1 that is, change the sort order to descending, then your operation would succeed and you'd end up with another index on the city field, but sorted in descending order.
In step 5, we run the stats() function on the collection which can alternately be run as db.mockdata.runCommand('collstats') and save its output in a temporary variable called stats. If we inspect the totalIndexSizeand indexSizes keys, we can find the total as well as index specific sizes, respectively. At this point, I would strongly suggest you have a look at other keys in the output. It should give you a peek into the low-level internals of how MongoDB manages each collection.
Lastly, in step 6, we re-index an existing index. In that, it drops the existing index and rebuilds it either in the foreground or background, depending on how it was set up initially. It is usually not necessary to rebuild the index, however, as per MongoDB's documentation you may choose to do so if you feel that the index size may be disproportionate or your collection has significantly grown in size.
- C++程序設(shè)計(jì)(第3版)
- JavaScript語言精髓與編程實(shí)踐(第3版)
- 樂學(xué)Web編程:網(wǎng)站制作不神秘
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Python Network Programming Cookbook(Second Edition)
- Python程序設(shè)計(jì)
- Elasticsearch for Hadoop
- 第一行代碼 C語言(視頻講解版)
- Building Serverless Architectures
- Angular應(yīng)用程序開發(fā)指南
- Java編程從入門到精通
- NGUI for Unity
- 實(shí)戰(zhàn)Python網(wǎng)絡(luò)爬蟲
- Microsoft XNA 4.0 Game Development Cookbook
- Python程序員面試算法寶典