Chapter 2 MongoDB through the JavaScript shell

个人博客,喜欢的可以收藏

This chapter covers:

  • Using CRUD Operations in the MongoDB shell
  • Building indexes and using explain()
  • Understanding basic adminstration
  • Getting help

2.2.1 Starting the shell

start the MongoDB shell by running the mongo executable:

mongo

2.1.2 Databases, collections, and documents

MongoDB needs a way to group documents,similar to a table in an RDBMS,In MongoDB , this is called a collection.

2.1.3 Insert and queries


> show dbs
admin     0.000GB
config    0.000GB
local     0.000GB
tutorial  0.000GB
> use tutorial
switched to db tutorial
> db.users.find()
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
{ "_id" : ObjectId("61a20f768bf9a69c72bda6fd"), "username" : "jones" }
> db.users.count()
2
> db.users.find({"username" : "switch"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
> db.users.find({"username" : "jones"})
{ "_id" : ObjectId("61a20f768bf9a69c72bda6fd"), "username" : "jones" }
> db.users.find({ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" })
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
> db.users.find({$and: [{_id : ObjectId("61a20f3f8bf9a69c72bda6fc")}, {username : "switch"}]})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
> db.users.find({ $or : [{username:"switch" },{username: "jones" }]})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
{ "_id" : ObjectId("61a20f768bf9a69c72bda6fd"), "username" : "jones" }
>

 

2.1.4 Update documents

All updates require at least two arguments. The first specifies which documents to update, and the second defines how the selected documents should be modified. Keep in mind that by default the update() method updates a single document.

There are two types of updates:

  • One type of update involves applying modification operations to a document or documents.
  • The other type involves replacing the old document with a new one.

Operator update:

> db.users.find({username:"switch"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
>
> db.users.update({username:"switch"},{$set:{country:"Canada"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({username:"switch"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch", "country" : "Canada" }
>

Replacement update

> db.users.update({username:"switch"},{$set:{country:"Canada"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({username:"switch"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch", "country" : "Canada" }
>

> db.users.update({username:"switch"},{country:"Canada"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({country:"Canada"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "country" : "Canada" }
> db.users.update({country:"Canada"},{$set:{username: "switch"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({country:"Canada"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "country" : "Canada", "username" : "switch" }
> db.users.update({username:"switch"},{$unset:{country: 1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({username:"switch"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch" }
>

UPDATING COMPLEX DATA

pretty() is actually cursor.pretty(),which is a way of configuring a cursor to display results in an easy-to-read format.

More Advanced Updates

you're better using either $push or $addToSet. Both operators add an item to an array,but the second does so uniquely,preventing a duplicate addition.

> db.users.find({"favorites.movies": "Casablanca"})
{ "_id" : ObjectId("61a20f3f8bf9a69c72bda6fc"), "username" : "switch", "favorites" : { "cities" : [ "Chicago", "Cheyenne" ], "movies" : [ "Casablanca", "For a Few Dollars More", "The Sting" ] } }
{ "_id" : ObjectId("61a20f768bf9a69c72bda6fd"), "username" : "jones", "favorites" : { "movies" : [ "Casablanca", "Rocky" ] } }
>
>
> db.users.update( {"favorites.movies": "Casablanca"},
...     {$addToSet: {"favorites.movies": "The Maltese Falcon"}},
...           false,
...           true)

WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
>

 

2.1.5 Deleting data

If given no parameters, a remove operation will clear a collection of all its documents.a foo collection's contents, you enter:

> db.foo.remove()

> db.users.remove({"favorites.cities": "Cheyenne"})

Note that the remove() operation doesn't actually delete the collection;it merely remove documents from a collection.You can think of it as being analogous to SQL's DELETE command.

If your intent is to delete the collection along with all of its indexes,use the drop() method:


> db.user.drop()

2.1.6 Other shell features

 

2.2 Creating and querying with indexes

2.2.1 Creating a large collection

Range Queries

you can also issue range queries using the special $gt and $lt operators.

You can see that by using a simple JSON document,you're able to specify a range query in much the same way you might in SQL. $gt and $lt are only two of a host of operators that comprise the MongoDB query language.Others include $gte for greater than or equal to , $lte for less than or equal to , and $ne for not equal to .

 

2.2.2 Indexing and explain()

> db.numbers.find({num:{"$gt": 19995}}).explain("executionStats")

Listing2.1 Typical explain ("executionStats") output for an unindexed query

 

> db.numbers.createIndex({num:1})

> db.numbers.getIndexes()

 

Listing2.2 explain() output for an indexed query

 

2.3 Basic adminstration

2.3.1 Getting database information

show dbs prints a list of all the databases on the system:

> show dbs
admin     0.000GB
config    0.000GB
local     0.000GB
tutorial  0.001GB
>
> show collections
numbers
users
>
>
> db.stats()
{
        "db" : "tutorial",
        "collections" : 2,
        "views" : 0,
        "objects" : 20001,
        "avgObjSize" : 35.00464976751162,
        "dataSize" : 700128,
        "storageSize" : 299008,
        "numExtents" : 0,
        "indexes" : 3,
        "indexSize" : 471040,
        "scaleFactor" : 1,
        "fsUsedSize" : 5071294464,
        "fsTotalSize" : 85887791104,
        "ok" : 1
}
>
>
> db.numbers.stats()
{
        "ns" : "tutorial.numbers",
        "size" : 700000,
        "count" : 20000,
        "avgObjSize" : 35,
        "storageSize" : 262144,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
                "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                "type" : "file",
                "uri" : "statistics:table:collection-10-3079709718660801038",
                "LSM" : {
                        "bloom filter false positives" : 0,
                        "bloom filter hits" : 0,
                        "bloom filter misses" : 0,
                        "bloom filter pages evicted from cache" : 0,
                        "bloom filter pages read into cache" : 0,
                        "bloom filters in the LSM tree" : 0,
                        "chunks in the LSM tree" : 0,
                        "highest merge generation in the LSM tree" : 0,
                        "queries that could have benefited from a Bloom filter that did not exist" : 0,
                        "sleep for LSM checkpoint throttle" : 0,
                        "sleep for LSM merge throttle" : 0,
                        "total size of bloom filters" : 0
                },
                "block-manager" : {
                        "allocations requiring file extension" : 10,
                        "blocks allocated" : 10,
                        "blocks freed" : 0,
                        "checkpoint size" : 245760,
                        "file allocation unit size" : 4096,
                        "file bytes available for reuse" : 0,
                        "file magic number" : 120897,
                        "file major version number" : 1,
                        "file size in bytes" : 262144,
                        "minor version number" : 0
                },
                "btree" : {
                        "btree checkpoint generation" : 141,
                        "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                        "column-store fixed-size leaf pages" : 0,
                        "column-store internal pages" : 0,
                        "column-store variable-size RLE encoded values" : 0,
                        "column-store variable-size deleted values" : 0,
                        "column-store variable-size leaf pages" : 0,
                        "fixed-record size" : 0,
                        "maximum internal page key size" : 368,
                        "maximum internal page size" : 4096,
                        "maximum leaf page key size" : 2867,
                        "maximum leaf page size" : 32768,
                        "maximum leaf page value size" : 67108864,
                        "maximum tree depth" : 3,
                        "number of key/value pairs" : 0,
                        "overflow pages" : 0,
                        "pages rewritten by compaction" : 0,
                        "row-store empty values" : 0,
                        "row-store internal pages" : 0,
                        "row-store leaf pages" : 0
                },
                "cache" : {
                        "bytes currently in the cache" : 2706578,
                        "bytes dirty in the cache cumulative" : 908,
                        "bytes read into cache" : 0,
                        "bytes written from cache" : 791833,
                        "checkpoint blocked page eviction" : 0,
                        "data source pages selected for eviction unable to be evicted" : 0,
                        "eviction walk passes of a file" : 0,
                        "eviction walk target pages histogram - 0-9" : 0,
                        "eviction walk target pages histogram - 10-31" : 0,
                        "eviction walk target pages histogram - 128 and higher" : 0,
                        "eviction walk target pages histogram - 32-63" : 0,
                        "eviction walk target pages histogram - 64-128" : 0,
                        "eviction walks abandoned" : 0,
                        "eviction walks gave up because they restarted their walk twice" : 0,
                        "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                        "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                        "eviction walks reached end of tree" : 0,
                        "eviction walks started from root of tree" : 0,
                        "eviction walks started from saved location in tree" : 0,
                        "hazard pointer blocked page eviction" : 0,
                        "in-memory page passed criteria to be split" : 0,
                        "in-memory page splits" : 0,
                        "internal pages evicted" : 0,
                        "internal pages split during eviction" : 0,
                        "leaf pages split during eviction" : 0,
                        "modified pages evicted" : 0,
                        "overflow pages read into cache" : 0,
                        "page split during eviction deepened the tree" : 0,
                        "page written requiring cache overflow records" : 0,
                        "pages read into cache" : 0,
                        "pages read into cache after truncate" : 1,
                        "pages read into cache after truncate in prepare state" : 0,
                        "pages read into cache requiring cache overflow entries" : 0,
                        "pages requested from the cache" : 20787,
                        "pages seen by eviction walk" : 0,
                        "pages written from cache" : 8,
                        "pages written requiring in-memory restoration" : 0,
                        "tracked dirty bytes in the cache" : 0,
                        "unmodified pages evicted" : 0
                },
                "cache_walk" : {
                        "Average difference between current eviction generation when the page was last considered" : 0,
                        "Average on-disk page image size seen" : 0,
                        "Average time in cache for pages that have been visited by the eviction server" : 0,
                        "Average time in cache for pages that have not been visited by the eviction server" : 0,
                        "Clean pages currently in cache" : 0,
                        "Current eviction generation" : 0,
                        "Dirty pages currently in cache" : 0,
                        "Entries in the root page" : 0,
                        "Internal pages currently in cache" : 0,
                        "Leaf pages currently in cache" : 0,
                        "Maximum difference between current eviction generation when the page was last considered" : 0,
                        "Maximum page size seen" : 0,
                        "Minimum on-disk page image size seen" : 0,
                        "Number of pages never visited by eviction server" : 0,
                        "On-disk page image sizes smaller than a single allocation unit" : 0,
                        "Pages created in memory and never written" : 0,
                        "Pages currently queued for eviction" : 0,
                        "Pages that could not be queued for eviction" : 0,
                        "Refs skipped during cache traversal" : 0,
                        "Size of the root page" : 0,
                        "Total number of pages currently in cache" : 0
                },
                "compression" : {
                        "compressed page maximum internal page size prior to compression" : 4096,
                        "compressed page maximum leaf page size prior to compression " : 111416,
                        "compressed pages read" : 0,
                        "compressed pages written" : 7,
                        "page written failed to compress" : 0,
                        "page written was too small to compress" : 1
                },
                "cursor" : {
                        "bulk loaded cursor insert calls" : 0,
                        "cache cursors reuse count" : 20005,
                        "close calls that result in cache" : 0,
                        "create calls" : 3,
                        "insert calls" : 20000,
                        "insert key and value bytes" : 751426,
                        "modify" : 0,
                        "modify key and value bytes affected" : 0,
                        "modify value bytes modified" : 0,
                        "next calls" : 100106,
                        "open cursor count" : 0,
                        "operation restarted" : 0,
                        "prev calls" : 1,
                        "remove calls" : 0,
                        "remove key bytes removed" : 0,
                        "reserve calls" : 0,
                        "reset calls" : 40796,
                        "search calls" : 4,
                        "search near calls" : 780,
                        "truncate calls" : 0,
                        "update calls" : 0,
                        "update key and value bytes" : 0,
                        "update value size change" : 0
                },
                "reconciliation" : {
                        "dictionary matches" : 0,
                        "fast-path pages deleted" : 0,
                        "internal page key bytes discarded using suffix compression" : 13,
                        "internal page multi-block writes" : 0,
                        "internal-page overflow keys" : 0,
                        "leaf page key bytes discarded using prefix compression" : 0,
                        "leaf page multi-block writes" : 1,
                        "leaf-page overflow keys" : 0,
                        "maximum blocks required for a page" : 1,
                        "overflow values written" : 0,
                        "page checksum matches" : 0,
                        "page reconciliation calls" : 2,
                        "page reconciliation calls for eviction" : 0,
                        "pages deleted" : 0
                },
                "session" : {
                        "object compaction" : 0
                },
                "transaction" : {
                        "update conflicts" : 0
                }
        },
        "nindexes" : 2,
        "indexBuilds" : [ ],
        "totalIndexSize" : 434176,
        "indexSizes" : {
                "_id_" : 196608,
                "num_1" : 237568
        },
        "scaleFactor" : 1,
        "ok" : 1
}
>

2.3.2 How commands work

The stats() method is a helper that wraps the shell's command invocation method.


> db.stats()
{
        "db" : "tutorial",
        "collections" : 2,
        "views" : 0,
        "objects" : 20001,
        "avgObjSize" : 35.00464976751162,
        "dataSize" : 700128,
        "storageSize" : 299008,
        "numExtents" : 0,
        "indexes" : 3,
        "indexSize" : 471040,
        "scaleFactor" : 1,
        "fsUsedSize" : 5071298560,
        "fsTotalSize" : 85887791104,
        "ok" : 1
}
> db.runCommand({dbstats:1})
{
        "db" : "tutorial",
        "collections" : 2,
        "views" : 0,
        "objects" : 20001,
        "avgObjSize" : 35.00464976751162,
        "dataSize" : 700128,
        "storageSize" : 299008,
        "numExtents" : 0,
        "indexes" : 3,
        "indexSize" : 471040,
        "scaleFactor" : 1,
        "fsUsedSize" : 5071302656,
        "fsTotalSize" : 85887791104,
        "ok" : 1
}
> db.runCommand({collstats: "numbers"})
{
        "ns" : "tutorial.numbers",
        "size" : 700000,
        "count" : 20000,
        "avgObjSize" : 35,
        "storageSize" : 262144,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
                "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                "type" : "file",
                "uri" : "statistics:table:collection-10-3079709718660801038",
                "LSM" : {
                        "bloom filter false positives" : 0,
                        "bloom filter hits" : 0,
                        "bloom filter misses" : 0,
                        "bloom filter pages evicted from cache" : 0,
                        "bloom filter pages read into cache" : 0,
                        "bloom filters in the LSM tree" : 0,
                        "chunks in the LSM tree" : 0,
                        "highest merge generation in the LSM tree" : 0,
                        "queries that could have benefited from a Bloom filter that did not exist" : 0,
                        "sleep for LSM checkpoint throttle" : 0,
                        "sleep for LSM merge throttle" : 0,
                        "total size of bloom filters" : 0
                },
                "block-manager" : {
                        "allocations requiring file extension" : 10,
                        "blocks allocated" : 10,
                        "blocks freed" : 0,
                        "checkpoint size" : 245760,
                        "file allocation unit size" : 4096,
                        "file bytes available for reuse" : 0,
                        "file magic number" : 120897,
                        "file major version number" : 1,
                        "file size in bytes" : 262144,
                        "minor version number" : 0
                },
                "btree" : {
                        "btree checkpoint generation" : 145,
                        "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                        "column-store fixed-size leaf pages" : 0,
                        "column-store internal pages" : 0,
                        "column-store variable-size RLE encoded values" : 0,
                        "column-store variable-size deleted values" : 0,
                        "column-store variable-size leaf pages" : 0,
                        "fixed-record size" : 0,
                        "maximum internal page key size" : 368,
                        "maximum internal page size" : 4096,
                        "maximum leaf page key size" : 2867,
                        "maximum leaf page size" : 32768,
                        "maximum leaf page value size" : 67108864,
                        "maximum tree depth" : 3,
                        "number of key/value pairs" : 0,
                        "overflow pages" : 0,
                        "pages rewritten by compaction" : 0,
                        "row-store empty values" : 0,
                        "row-store internal pages" : 0,
                        "row-store leaf pages" : 0
                },
                "cache" : {
                        "bytes currently in the cache" : 2706578,
                        "bytes dirty in the cache cumulative" : 908,
                        "bytes read into cache" : 0,
                        "bytes written from cache" : 791833,
                        "checkpoint blocked page eviction" : 0,
                        "data source pages selected for eviction unable to be evicted" : 0,
                        "eviction walk passes of a file" : 0,
                        "eviction walk target pages histogram - 0-9" : 0,
                        "eviction walk target pages histogram - 10-31" : 0,
                        "eviction walk target pages histogram - 128 and higher" : 0,
                        "eviction walk target pages histogram - 32-63" : 0,
                        "eviction walk target pages histogram - 64-128" : 0,
                        "eviction walks abandoned" : 0,
                        "eviction walks gave up because they restarted their walk twice" : 0,
                        "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                        "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                        "eviction walks reached end of tree" : 0,
                        "eviction walks started from root of tree" : 0,
                        "eviction walks started from saved location in tree" : 0,
                        "hazard pointer blocked page eviction" : 0,
                        "in-memory page passed criteria to be split" : 0,
                        "in-memory page splits" : 0,
                        "internal pages evicted" : 0,
                        "internal pages split during eviction" : 0,
                        "leaf pages split during eviction" : 0,
                        "modified pages evicted" : 0,
                        "overflow pages read into cache" : 0,
                        "page split during eviction deepened the tree" : 0,
                        "page written requiring cache overflow records" : 0,
                        "pages read into cache" : 0,
                        "pages read into cache after truncate" : 1,
                        "pages read into cache after truncate in prepare state" : 0,
                        "pages read into cache requiring cache overflow entries" : 0,
                        "pages requested from the cache" : 20787,
                        "pages seen by eviction walk" : 0,
                        "pages written from cache" : 8,
                        "pages written requiring in-memory restoration" : 0,
                        "tracked dirty bytes in the cache" : 0,
                        "unmodified pages evicted" : 0
                },
                "cache_walk" : {
                        "Average difference between current eviction generation when the page was last considered" : 0,
                        "Average on-disk page image size seen" : 0,
                        "Average time in cache for pages that have been visited by the eviction server" : 0,
                        "Average time in cache for pages that have not been visited by the eviction server" : 0,
                        "Clean pages currently in cache" : 0,
                        "Current eviction generation" : 0,
                        "Dirty pages currently in cache" : 0,
                        "Entries in the root page" : 0,
                        "Internal pages currently in cache" : 0,
                        "Leaf pages currently in cache" : 0,
                        "Maximum difference between current eviction generation when the page was last considered" : 0,
                        "Maximum page size seen" : 0,
                        "Minimum on-disk page image size seen" : 0,
                        "Number of pages never visited by eviction server" : 0,
                        "On-disk page image sizes smaller than a single allocation unit" : 0,
                        "Pages created in memory and never written" : 0,
                        "Pages currently queued for eviction" : 0,
                        "Pages that could not be queued for eviction" : 0,
                        "Refs skipped during cache traversal" : 0,
                        "Size of the root page" : 0,
                        "Total number of pages currently in cache" : 0
                },
                "compression" : {
                        "compressed page maximum internal page size prior to compression" : 4096,
                        "compressed page maximum leaf page size prior to compression " : 111416,
                        "compressed pages read" : 0,
                        "compressed pages written" : 7,
                        "page written failed to compress" : 0,
                        "page written was too small to compress" : 1
                },
                "cursor" : {
                        "bulk loaded cursor insert calls" : 0,
                        "cache cursors reuse count" : 20005,
                        "close calls that result in cache" : 0,
                        "create calls" : 3,
                        "insert calls" : 20000,
                        "insert key and value bytes" : 751426,
                        "modify" : 0,
                        "modify key and value bytes affected" : 0,
                        "modify value bytes modified" : 0,
                        "next calls" : 100106,
                        "open cursor count" : 0,
                        "operation restarted" : 0,
                        "prev calls" : 1,
                        "remove calls" : 0,
                        "remove key bytes removed" : 0,
                        "reserve calls" : 0,
                        "reset calls" : 40796,
                        "search calls" : 4,
                        "search near calls" : 780,
                        "truncate calls" : 0,
                        "update calls" : 0,
                        "update key and value bytes" : 0,
                        "update value size change" : 0
                },
                "reconciliation" : {
                        "dictionary matches" : 0,
                        "fast-path pages deleted" : 0,
                        "internal page key bytes discarded using suffix compression" : 13,
                        "internal page multi-block writes" : 0,
                        "internal-page overflow keys" : 0,
                        "leaf page key bytes discarded using prefix compression" : 0,
                        "leaf page multi-block writes" : 1,
                        "leaf-page overflow keys" : 0,
                        "maximum blocks required for a page" : 1,
                        "overflow values written" : 0,
                        "page checksum matches" : 0,
                        "page reconciliation calls" : 2,
                        "page reconciliation calls for eviction" : 0,
                        "pages deleted" : 0
                },
                "session" : {
                        "object compaction" : 0
                },
                "transaction" : {
                        "update conflicts" : 0
                }
        },
        "nindexes" : 2,
        "indexDetails" : {
                "_id_" : {
                        "metadata" : {
                                "formatVersion" : 8
                        },
                        "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=8),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                        "type" : "file",
                        "uri" : "statistics:table:index-11-3079709718660801038",
                        "LSM" : {
                                "bloom filter false positives" : 0,
                                "bloom filter hits" : 0,
                                "bloom filter misses" : 0,
                                "bloom filter pages evicted from cache" : 0,
                                "bloom filter pages read into cache" : 0,
                                "bloom filters in the LSM tree" : 0,
                                "chunks in the LSM tree" : 0,
                                "highest merge generation in the LSM tree" : 0,
                                "queries that could have benefited from a Bloom filter that did not exist" : 0,
                                "sleep for LSM checkpoint throttle" : 0,
                                "sleep for LSM merge throttle" : 0,
                                "total size of bloom filters" : 0
                        },
                        "block-manager" : {
                                "allocations requiring file extension" : 14,
                                "blocks allocated" : 14,
                                "blocks freed" : 0,
                                "checkpoint size" : 180224,
                                "file allocation unit size" : 4096,
                                "file bytes available for reuse" : 0,
                                "file magic number" : 120897,
                                "file major version number" : 1,
                                "file size in bytes" : 196608,
                                "minor version number" : 0
                        },
                        "btree" : {
                                "btree checkpoint generation" : 145,
                                "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                                "column-store fixed-size leaf pages" : 0,
                                "column-store internal pages" : 0,
                                "column-store variable-size RLE encoded values" : 0,
                                "column-store variable-size deleted values" : 0,
                                "column-store variable-size leaf pages" : 0,
                                "fixed-record size" : 0,
                                "maximum internal page key size" : 1474,
                                "maximum internal page size" : 16384,
                                "maximum leaf page key size" : 1474,
                                "maximum leaf page size" : 16384,
                                "maximum leaf page value size" : 7372,
                                "maximum tree depth" : 3,
                                "number of key/value pairs" : 0,
                                "overflow pages" : 0,
                                "pages rewritten by compaction" : 0,
                                "row-store empty values" : 0,
                                "row-store internal pages" : 0,
                                "row-store leaf pages" : 0
                        },
                        "cache" : {
                                "bytes currently in the cache" : 2259698,
                                "bytes dirty in the cache cumulative" : 908,
                                "bytes read into cache" : 0,
                                "bytes written from cache" : 160066,
                                "checkpoint blocked page eviction" : 0,
                                "data source pages selected for eviction unable to be evicted" : 0,
                                "eviction walk passes of a file" : 0,
                                "eviction walk target pages histogram - 0-9" : 0,
                                "eviction walk target pages histogram - 10-31" : 0,
                                "eviction walk target pages histogram - 128 and higher" : 0,
                                "eviction walk target pages histogram - 32-63" : 0,
                                "eviction walk target pages histogram - 64-128" : 0,
                                "eviction walks abandoned" : 0,
                                "eviction walks gave up because they restarted their walk twice" : 0,
                                "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                                "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                                "eviction walks reached end of tree" : 0,
                                "eviction walks started from root of tree" : 0,
                                "eviction walks started from saved location in tree" : 0,
                                "hazard pointer blocked page eviction" : 0,
                                "in-memory page passed criteria to be split" : 0,
                                "in-memory page splits" : 0,
                                "internal pages evicted" : 0,
                                "internal pages split during eviction" : 0,
                                "leaf pages split during eviction" : 0,
                                "modified pages evicted" : 0,
                                "overflow pages read into cache" : 0,
                                "page split during eviction deepened the tree" : 0,
                                "page written requiring cache overflow records" : 0,
                                "pages read into cache" : 0,
                                "pages read into cache after truncate" : 1,
                                "pages read into cache after truncate in prepare state" : 0,
                                "pages read into cache requiring cache overflow entries" : 0,
                                "pages requested from the cache" : 20000,
                                "pages seen by eviction walk" : 0,
                                "pages written from cache" : 12,
                                "pages written requiring in-memory restoration" : 0,
                                "tracked dirty bytes in the cache" : 0,
                                "unmodified pages evicted" : 0
                        },
                        "cache_walk" : {
                                "Average difference between current eviction generation when the page was last considered" : 0,
                                "Average on-disk page image size seen" : 0,
                                "Average time in cache for pages that have been visited by the eviction server" : 0,
                                "Average time in cache for pages that have not been visited by the eviction server" : 0,
                                "Clean pages currently in cache" : 0,
                                "Current eviction generation" : 0,
                                "Dirty pages currently in cache" : 0,
                                "Entries in the root page" : 0,
                                "Internal pages currently in cache" : 0,
                                "Leaf pages currently in cache" : 0,
                                "Maximum difference between current eviction generation when the page was last considered" : 0,
                                "Maximum page size seen" : 0,
                                "Minimum on-disk page image size seen" : 0,
                                "Number of pages never visited by eviction server" : 0,
                                "On-disk page image sizes smaller than a single allocation unit" : 0,
                                "Pages created in memory and never written" : 0,
                                "Pages currently queued for eviction" : 0,
                                "Pages that could not be queued for eviction" : 0,
                                "Refs skipped during cache traversal" : 0,
                                "Size of the root page" : 0,
                                "Total number of pages currently in cache" : 0
                        },
                        "compression" : {
                                "compressed page maximum internal page size prior to compression" : 16384,
                                "compressed page maximum leaf page size prior to compression " : 16384,
                                "compressed pages read" : 0,
                                "compressed pages written" : 0,
                                "page written failed to compress" : 0,
                                "page written was too small to compress" : 0
                        },
                        "cursor" : {
                                "bulk loaded cursor insert calls" : 0,
                                "cache cursors reuse count" : 19998,
                                "close calls that result in cache" : 0,
                                "create calls" : 2,
                                "insert calls" : 20000,
                                "insert key and value bytes" : 338977,
                                "modify" : 0,
                                "modify key and value bytes affected" : 0,
                                "modify value bytes modified" : 0,
                                "next calls" : 0,
                                "open cursor count" : 0,
                                "operation restarted" : 0,
                                "prev calls" : 0,
                                "remove calls" : 0,
                                "remove key bytes removed" : 0,
                                "reserve calls" : 0,
                                "reset calls" : 40000,
                                "search calls" : 0,
                                "search near calls" : 0,
                                "truncate calls" : 0,
                                "update calls" : 0,
                                "update key and value bytes" : 0,
                                "update value size change" : 0
                        },
                        "reconciliation" : {
                                "dictionary matches" : 0,
                                "fast-path pages deleted" : 0,
                                "internal page key bytes discarded using suffix compression" : 42,
                                "internal page multi-block writes" : 0,
                                "internal-page overflow keys" : 0,
                                "leaf page key bytes discarded using prefix compression" : 239862,
                                "leaf page multi-block writes" : 1,
                                "leaf-page overflow keys" : 0,
                                "maximum blocks required for a page" : 1,
                                "overflow values written" : 0,
                                "page checksum matches" : 0,
                                "page reconciliation calls" : 2,
                                "page reconciliation calls for eviction" : 0,
                                "pages deleted" : 0
                        },
                        "session" : {
                                "object compaction" : 0
                        },
                        "transaction" : {
                                "update conflicts" : 0
                        }
                },
                "num_1" : {
                        "metadata" : {
                                "formatVersion" : 8
                        },
                        "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=8),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                        "type" : "file",
                        "uri" : "statistics:table:index-12-3079709718660801038",
                        "LSM" : {
                                "bloom filter false positives" : 0,
                                "bloom filter hits" : 0,
                                "bloom filter misses" : 0,
                                "bloom filter pages evicted from cache" : 0,
                                "bloom filter pages read into cache" : 0,
                                "bloom filters in the LSM tree" : 0,
                                "chunks in the LSM tree" : 0,
                                "highest merge generation in the LSM tree" : 0,
                                "queries that could have benefited from a Bloom filter that did not exist" : 0,
                                "sleep for LSM checkpoint throttle" : 0,
                                "sleep for LSM merge throttle" : 0,
                                "total size of bloom filters" : 0
                        },
                        "block-manager" : {
                                "allocations requiring file extension" : 0,
                                "blocks allocated" : 0,
                                "blocks freed" : 0,
                                "checkpoint size" : 221184,
                                "file allocation unit size" : 4096,
                                "file bytes available for reuse" : 0,
                                "file magic number" : 120897,
                                "file major version number" : 1,
                                "file size in bytes" : 237568,
                                "minor version number" : 0
                        },
                        "btree" : {
                                "btree checkpoint generation" : 145,
                                "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                                "column-store fixed-size leaf pages" : 0,
                                "column-store internal pages" : 0,
                                "column-store variable-size RLE encoded values" : 0,
                                "column-store variable-size deleted values" : 0,
                                "column-store variable-size leaf pages" : 0,
                                "fixed-record size" : 0,
                                "maximum internal page key size" : 1474,
                                "maximum internal page size" : 16384,
                                "maximum leaf page key size" : 1474,
                                "maximum leaf page size" : 16384,
                                "maximum leaf page value size" : 7372,
                                "maximum tree depth" : 3,
                                "number of key/value pairs" : 0,
                                "overflow pages" : 0,
                                "pages rewritten by compaction" : 0,
                                "row-store empty values" : 0,
                                "row-store internal pages" : 0,
                                "row-store leaf pages" : 0
                        },
                        "cache" : {
                                "bytes currently in the cache" : 16504,
                                "bytes dirty in the cache cumulative" : 0,
                                "bytes read into cache" : 8010,
                                "bytes written from cache" : 0,
                                "checkpoint blocked page eviction" : 0,
                                "data source pages selected for eviction unable to be evicted" : 0,
                                "eviction walk passes of a file" : 0,
                                "eviction walk target pages histogram - 0-9" : 0,
                                "eviction walk target pages histogram - 10-31" : 0,
                                "eviction walk target pages histogram - 128 and higher" : 0,
                                "eviction walk target pages histogram - 32-63" : 0,
                                "eviction walk target pages histogram - 64-128" : 0,
                                "eviction walks abandoned" : 0,
                                "eviction walks gave up because they restarted their walk twice" : 0,
                                "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                                "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                                "eviction walks reached end of tree" : 0,
                                "eviction walks started from root of tree" : 0,
                                "eviction walks started from saved location in tree" : 0,
                                "hazard pointer blocked page eviction" : 0,
                                "in-memory page passed criteria to be split" : 0,
                                "in-memory page splits" : 0,
                                "internal pages evicted" : 0,
                                "internal pages split during eviction" : 0,
                                "leaf pages split during eviction" : 0,
                                "modified pages evicted" : 0,
                                "overflow pages read into cache" : 0,
                                "page split during eviction deepened the tree" : 0,
                                "page written requiring cache overflow records" : 0,
                                "pages read into cache" : 2,
                                "pages read into cache after truncate" : 0,
                                "pages read into cache after truncate in prepare state" : 0,
                                "pages read into cache requiring cache overflow entries" : 0,
                                "pages requested from the cache" : 1,
                                "pages seen by eviction walk" : 0,
                                "pages written from cache" : 0,
                                "pages written requiring in-memory restoration" : 0,
                                "tracked dirty bytes in the cache" : 0,
                                "unmodified pages evicted" : 0
                        },
                        "cache_walk" : {
                                "Average difference between current eviction generation when the page was last considered" : 0,
                                "Average on-disk page image size seen" : 0,
                                "Average time in cache for pages that have been visited by the eviction server" : 0,
                                "Average time in cache for pages that have not been visited by the eviction server" : 0,
                                "Clean pages currently in cache" : 0,
                                "Current eviction generation" : 0,
                                "Dirty pages currently in cache" : 0,
                                "Entries in the root page" : 0,
                                "Internal pages currently in cache" : 0,
                                "Leaf pages currently in cache" : 0,
                                "Maximum difference between current eviction generation when the page was last considered" : 0,
                                "Maximum page size seen" : 0,
                                "Minimum on-disk page image size seen" : 0,
                                "Number of pages never visited by eviction server" : 0,
                                "On-disk page image sizes smaller than a single allocation unit" : 0,
                                "Pages created in memory and never written" : 0,
                                "Pages currently queued for eviction" : 0,
                                "Pages that could not be queued for eviction" : 0,
                                "Refs skipped during cache traversal" : 0,
                                "Size of the root page" : 0,
                                "Total number of pages currently in cache" : 0
                        },
                        "compression" : {
                                "compressed page maximum internal page size prior to compression" : 16384,
                                "compressed page maximum leaf page size prior to compression " : 16384,
                                "compressed pages read" : 0,
                                "compressed pages written" : 0,
                                "page written failed to compress" : 0,
                                "page written was too small to compress" : 0
                        },
                        "cursor" : {
                                "bulk loaded cursor insert calls" : 0,
                                "cache cursors reuse count" : 0,
                                "close calls that result in cache" : 0,
                                "create calls" : 1,
                                "insert calls" : 0,
                                "insert key and value bytes" : 0,
                                "modify" : 0,
                                "modify key and value bytes affected" : 0,
                                "modify value bytes modified" : 0,
                                "next calls" : 5,
                                "open cursor count" : 0,
                                "operation restarted" : 0,
                                "prev calls" : 0,
                                "remove calls" : 0,
                                "remove key bytes removed" : 0,
                                "reserve calls" : 0,
                                "reset calls" : 2,
                                "search calls" : 0,
                                "search near calls" : 1,
                                "truncate calls" : 0,
                                "update calls" : 0,
                                "update key and value bytes" : 0,
                                "update value size change" : 0
                        },
                        "reconciliation" : {
                                "dictionary matches" : 0,
                                "fast-path pages deleted" : 0,
                                "internal page key bytes discarded using suffix compression" : 0,
                                "internal page multi-block writes" : 0,
                                "internal-page overflow keys" : 0,
                                "leaf page key bytes discarded using prefix compression" : 0,
                                "leaf page multi-block writes" : 0,
                                "leaf-page overflow keys" : 0,
                                "maximum blocks required for a page" : 0,
                                "overflow values written" : 0,
                                "page checksum matches" : 0,
                                "page reconciliation calls" : 0,
                                "page reconciliation calls for eviction" : 0,
                                "pages deleted" : 0
                        },
                        "session" : {
                                "object compaction" : 0
                        },
                        "transaction" : {
                                "update conflicts" : 0
                        }
                }
        },
        "indexBuilds" : [ ],
        "totalIndexSize" : 434176,
        "indexSizes" : {
                "_id_" : 196608,
                "num_1" : 237568
        },
        "scaleFactor" : 1,
        "ok" : 1
}
>
> db.runCommand
function(obj, extra, queryOptions) {
    "use strict";

    // Support users who call this function with a string commandName, e.g.
    // db.runCommand("commandName", {arg1: "value", arg2: "value"}).
    var mergedObj = this._mergeCommandOptions(obj, extra);

    // if options were passed (i.e. because they were overridden on a collection), use them.
    // Otherwise use getQueryOptions.
    var options = (typeof (queryOptions) !== "undefined") ? queryOptions : this.getQueryOptions();

    try {
        return this._runCommandImpl(this._name, mergedObj, options);
    } catch (ex) {
        // When runCommand flowed through query, a connection error resulted in the message
        // "error doing query: failed". Even though this message is arguably incorrect
        // for a command failing due to a connection failure, we preserve it for backwards
        // compatibility. See SERVER-18334 for details.
        if (ex.message.indexOf("network error") >= 0) {
            throw new Error("error doing query: failed: " + ex.message);
        }
        throw ex;
    }
}
>
>
> db.$cmd.findOne({collstats: "numbers"});
{
        "ns" : "tutorial.numbers",
        "size" : 700000,
        "count" : 20000,
        "avgObjSize" : 35,
        "storageSize" : 262144,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
                "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                "type" : "file",
                "uri" : "statistics:table:collection-10-3079709718660801038",
                "LSM" : {
                        "bloom filter false positives" : 0,
                        "bloom filter hits" : 0,
                        "bloom filter misses" : 0,
                        "bloom filter pages evicted from cache" : 0,
                        "bloom filter pages read into cache" : 0,
                        "bloom filters in the LSM tree" : 0,
                        "chunks in the LSM tree" : 0,
                        "highest merge generation in the LSM tree" : 0,
                        "queries that could have benefited from a Bloom filter that did not exist" : 0,
                        "sleep for LSM checkpoint throttle" : 0,
                        "sleep for LSM merge throttle" : 0,
                        "total size of bloom filters" : 0
                },
                "block-manager" : {
                        "allocations requiring file extension" : 10,
                        "blocks allocated" : 10,
                        "blocks freed" : 0,
                        "checkpoint size" : 245760,
                        "file allocation unit size" : 4096,
                        "file bytes available for reuse" : 0,
                        "file magic number" : 120897,
                        "file major version number" : 1,
                        "file size in bytes" : 262144,
                        "minor version number" : 0
                },
                "btree" : {
                        "btree checkpoint generation" : 147,
                        "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                        "column-store fixed-size leaf pages" : 0,
                        "column-store internal pages" : 0,
                        "column-store variable-size RLE encoded values" : 0,
                        "column-store variable-size deleted values" : 0,
                        "column-store variable-size leaf pages" : 0,
                        "fixed-record size" : 0,
                        "maximum internal page key size" : 368,
                        "maximum internal page size" : 4096,
                        "maximum leaf page key size" : 2867,
                        "maximum leaf page size" : 32768,
                        "maximum leaf page value size" : 67108864,
                        "maximum tree depth" : 3,
                        "number of key/value pairs" : 0,
                        "overflow pages" : 0,
                        "pages rewritten by compaction" : 0,
                        "row-store empty values" : 0,
                        "row-store internal pages" : 0,
                        "row-store leaf pages" : 0
                },
                "cache" : {
                        "bytes currently in the cache" : 2706578,
                        "bytes dirty in the cache cumulative" : 908,
                        "bytes read into cache" : 0,
                        "bytes written from cache" : 791833,
                        "checkpoint blocked page eviction" : 0,
                        "data source pages selected for eviction unable to be evicted" : 0,
                        "eviction walk passes of a file" : 0,
                        "eviction walk target pages histogram - 0-9" : 0,
                        "eviction walk target pages histogram - 10-31" : 0,
                        "eviction walk target pages histogram - 128 and higher" : 0,
                        "eviction walk target pages histogram - 32-63" : 0,
                        "eviction walk target pages histogram - 64-128" : 0,
                        "eviction walks abandoned" : 0,
                        "eviction walks gave up because they restarted their walk twice" : 0,
                        "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                        "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                        "eviction walks reached end of tree" : 0,
                        "eviction walks started from root of tree" : 0,
                        "eviction walks started from saved location in tree" : 0,
                        "hazard pointer blocked page eviction" : 0,
                        "in-memory page passed criteria to be split" : 0,
                        "in-memory page splits" : 0,
                        "internal pages evicted" : 0,
                        "internal pages split during eviction" : 0,
                        "leaf pages split during eviction" : 0,
                        "modified pages evicted" : 0,
                        "overflow pages read into cache" : 0,
                        "page split during eviction deepened the tree" : 0,
                        "page written requiring cache overflow records" : 0,
                        "pages read into cache" : 0,
                        "pages read into cache after truncate" : 1,
                        "pages read into cache after truncate in prepare state" : 0,
                        "pages read into cache requiring cache overflow entries" : 0,
                        "pages requested from the cache" : 20787,
                        "pages seen by eviction walk" : 0,
                        "pages written from cache" : 8,
                        "pages written requiring in-memory restoration" : 0,
                        "tracked dirty bytes in the cache" : 0,
                        "unmodified pages evicted" : 0
                },
                "cache_walk" : {
                        "Average difference between current eviction generation when the page was last considered" : 0,
                        "Average on-disk page image size seen" : 0,
                        "Average time in cache for pages that have been visited by the eviction server" : 0,
                        "Average time in cache for pages that have not been visited by the eviction server" : 0,
                        "Clean pages currently in cache" : 0,
                        "Current eviction generation" : 0,
                        "Dirty pages currently in cache" : 0,
                        "Entries in the root page" : 0,
                        "Internal pages currently in cache" : 0,
                        "Leaf pages currently in cache" : 0,
                        "Maximum difference between current eviction generation when the page was last considered" : 0,
                        "Maximum page size seen" : 0,
                        "Minimum on-disk page image size seen" : 0,
                        "Number of pages never visited by eviction server" : 0,
                        "On-disk page image sizes smaller than a single allocation unit" : 0,
                        "Pages created in memory and never written" : 0,
                        "Pages currently queued for eviction" : 0,
                        "Pages that could not be queued for eviction" : 0,
                        "Refs skipped during cache traversal" : 0,
                        "Size of the root page" : 0,
                        "Total number of pages currently in cache" : 0
                },
                "compression" : {
                        "compressed page maximum internal page size prior to compression" : 4096,
                        "compressed page maximum leaf page size prior to compression " : 111416,
                        "compressed pages read" : 0,
                        "compressed pages written" : 7,
                        "page written failed to compress" : 0,
                        "page written was too small to compress" : 1
                },
                "cursor" : {
                        "bulk loaded cursor insert calls" : 0,
                        "cache cursors reuse count" : 20005,
                        "close calls that result in cache" : 0,
                        "create calls" : 3,
                        "insert calls" : 20000,
                        "insert key and value bytes" : 751426,
                        "modify" : 0,
                        "modify key and value bytes affected" : 0,
                        "modify value bytes modified" : 0,
                        "next calls" : 100106,
                        "open cursor count" : 0,
                        "operation restarted" : 0,
                        "prev calls" : 1,
                        "remove calls" : 0,
                        "remove key bytes removed" : 0,
                        "reserve calls" : 0,
                        "reset calls" : 40796,
                        "search calls" : 4,
                        "search near calls" : 780,
                        "truncate calls" : 0,
                        "update calls" : 0,
                        "update key and value bytes" : 0,
                        "update value size change" : 0
                },
                "reconciliation" : {
                        "dictionary matches" : 0,
                        "fast-path pages deleted" : 0,
                        "internal page key bytes discarded using suffix compression" : 13,
                        "internal page multi-block writes" : 0,
                        "internal-page overflow keys" : 0,
                        "leaf page key bytes discarded using prefix compression" : 0,
                        "leaf page multi-block writes" : 1,
                        "leaf-page overflow keys" : 0,
                        "maximum blocks required for a page" : 1,
                        "overflow values written" : 0,
                        "page checksum matches" : 0,
                        "page reconciliation calls" : 2,
                        "page reconciliation calls for eviction" : 0,
                        "pages deleted" : 0
                },
                "session" : {
                        "object compaction" : 0
                },
                "transaction" : {
                        "update conflicts" : 0
                }
        },
        "nindexes" : 2,
        "indexDetails" : {
                "_id_" : {
                        "metadata" : {
                                "formatVersion" : 8
                        },
                        "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=8),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                        "type" : "file",
                        "uri" : "statistics:table:index-11-3079709718660801038",
                        "LSM" : {
                                "bloom filter false positives" : 0,
                                "bloom filter hits" : 0,
                                "bloom filter misses" : 0,
                                "bloom filter pages evicted from cache" : 0,
                                "bloom filter pages read into cache" : 0,
                                "bloom filters in the LSM tree" : 0,
                                "chunks in the LSM tree" : 0,
                                "highest merge generation in the LSM tree" : 0,
                                "queries that could have benefited from a Bloom filter that did not exist" : 0,
                                "sleep for LSM checkpoint throttle" : 0,
                                "sleep for LSM merge throttle" : 0,
                                "total size of bloom filters" : 0
                        },
                        "block-manager" : {
                                "allocations requiring file extension" : 14,
                                "blocks allocated" : 14,
                                "blocks freed" : 0,
                                "checkpoint size" : 180224,
                                "file allocation unit size" : 4096,
                                "file bytes available for reuse" : 0,
                                "file magic number" : 120897,
                                "file major version number" : 1,
                                "file size in bytes" : 196608,
                                "minor version number" : 0
                        },
                        "btree" : {
                                "btree checkpoint generation" : 147,
                                "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                                "column-store fixed-size leaf pages" : 0,
                                "column-store internal pages" : 0,
                                "column-store variable-size RLE encoded values" : 0,
                                "column-store variable-size deleted values" : 0,
                                "column-store variable-size leaf pages" : 0,
                                "fixed-record size" : 0,
                                "maximum internal page key size" : 1474,
                                "maximum internal page size" : 16384,
                                "maximum leaf page key size" : 1474,
                                "maximum leaf page size" : 16384,
                                "maximum leaf page value size" : 7372,
                                "maximum tree depth" : 3,
                                "number of key/value pairs" : 0,
                                "overflow pages" : 0,
                                "pages rewritten by compaction" : 0,
                                "row-store empty values" : 0,
                                "row-store internal pages" : 0,
                                "row-store leaf pages" : 0
                        },
                        "cache" : {
                                "bytes currently in the cache" : 2259698,
                                "bytes dirty in the cache cumulative" : 908,
                                "bytes read into cache" : 0,
                                "bytes written from cache" : 160066,
                                "checkpoint blocked page eviction" : 0,
                                "data source pages selected for eviction unable to be evicted" : 0,
                                "eviction walk passes of a file" : 0,
                                "eviction walk target pages histogram - 0-9" : 0,
                                "eviction walk target pages histogram - 10-31" : 0,
                                "eviction walk target pages histogram - 128 and higher" : 0,
                                "eviction walk target pages histogram - 32-63" : 0,
                                "eviction walk target pages histogram - 64-128" : 0,
                                "eviction walks abandoned" : 0,
                                "eviction walks gave up because they restarted their walk twice" : 0,
                                "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                                "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                                "eviction walks reached end of tree" : 0,
                                "eviction walks started from root of tree" : 0,
                                "eviction walks started from saved location in tree" : 0,
                                "hazard pointer blocked page eviction" : 0,
                                "in-memory page passed criteria to be split" : 0,
                                "in-memory page splits" : 0,
                                "internal pages evicted" : 0,
                                "internal pages split during eviction" : 0,
                                "leaf pages split during eviction" : 0,
                                "modified pages evicted" : 0,
                                "overflow pages read into cache" : 0,
                                "page split during eviction deepened the tree" : 0,
                                "page written requiring cache overflow records" : 0,
                                "pages read into cache" : 0,
                                "pages read into cache after truncate" : 1,
                                "pages read into cache after truncate in prepare state" : 0,
                                "pages read into cache requiring cache overflow entries" : 0,
                                "pages requested from the cache" : 20000,
                                "pages seen by eviction walk" : 0,
                                "pages written from cache" : 12,
                                "pages written requiring in-memory restoration" : 0,
                                "tracked dirty bytes in the cache" : 0,
                                "unmodified pages evicted" : 0
                        },
                        "cache_walk" : {
                                "Average difference between current eviction generation when the page was last considered" : 0,
                                "Average on-disk page image size seen" : 0,
                                "Average time in cache for pages that have been visited by the eviction server" : 0,
                                "Average time in cache for pages that have not been visited by the eviction server" : 0,
                                "Clean pages currently in cache" : 0,
                                "Current eviction generation" : 0,
                                "Dirty pages currently in cache" : 0,
                                "Entries in the root page" : 0,
                                "Internal pages currently in cache" : 0,
                                "Leaf pages currently in cache" : 0,
                                "Maximum difference between current eviction generation when the page was last considered" : 0,
                                "Maximum page size seen" : 0,
                                "Minimum on-disk page image size seen" : 0,
                                "Number of pages never visited by eviction server" : 0,
                                "On-disk page image sizes smaller than a single allocation unit" : 0,
                                "Pages created in memory and never written" : 0,
                                "Pages currently queued for eviction" : 0,
                                "Pages that could not be queued for eviction" : 0,
                                "Refs skipped during cache traversal" : 0,
                                "Size of the root page" : 0,
                                "Total number of pages currently in cache" : 0
                        },
                        "compression" : {
                                "compressed page maximum internal page size prior to compression" : 16384,
                                "compressed page maximum leaf page size prior to compression " : 16384,
                                "compressed pages read" : 0,
                                "compressed pages written" : 0,
                                "page written failed to compress" : 0,
                                "page written was too small to compress" : 0
                        },
                        "cursor" : {
                                "bulk loaded cursor insert calls" : 0,
                                "cache cursors reuse count" : 19998,
                                "close calls that result in cache" : 0,
                                "create calls" : 2,
                                "insert calls" : 20000,
                                "insert key and value bytes" : 338977,
                                "modify" : 0,
                                "modify key and value bytes affected" : 0,
                                "modify value bytes modified" : 0,
                                "next calls" : 0,
                                "open cursor count" : 0,
                                "operation restarted" : 0,
                                "prev calls" : 0,
                                "remove calls" : 0,
                                "remove key bytes removed" : 0,
                                "reserve calls" : 0,
                                "reset calls" : 40000,
                                "search calls" : 0,
                                "search near calls" : 0,
                                "truncate calls" : 0,
                                "update calls" : 0,
                                "update key and value bytes" : 0,
                                "update value size change" : 0
                        },
                        "reconciliation" : {
                                "dictionary matches" : 0,
                                "fast-path pages deleted" : 0,
                                "internal page key bytes discarded using suffix compression" : 42,
                                "internal page multi-block writes" : 0,
                                "internal-page overflow keys" : 0,
                                "leaf page key bytes discarded using prefix compression" : 239862,
                                "leaf page multi-block writes" : 1,
                                "leaf-page overflow keys" : 0,
                                "maximum blocks required for a page" : 1,
                                "overflow values written" : 0,
                                "page checksum matches" : 0,
                                "page reconciliation calls" : 2,
                                "page reconciliation calls for eviction" : 0,
                                "pages deleted" : 0
                        },
                        "session" : {
                                "object compaction" : 0
                        },
                        "transaction" : {
                                "update conflicts" : 0
                        }
                },
                "num_1" : {
                        "metadata" : {
                                "formatVersion" : 8
                        },
                        "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=8),assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                        "type" : "file",
                        "uri" : "statistics:table:index-12-3079709718660801038",
                        "LSM" : {
                                "bloom filter false positives" : 0,
                                "bloom filter hits" : 0,
                                "bloom filter misses" : 0,
                                "bloom filter pages evicted from cache" : 0,
                                "bloom filter pages read into cache" : 0,
                                "bloom filters in the LSM tree" : 0,
                                "chunks in the LSM tree" : 0,
                                "highest merge generation in the LSM tree" : 0,
                                "queries that could have benefited from a Bloom filter that did not exist" : 0,
                                "sleep for LSM checkpoint throttle" : 0,
                                "sleep for LSM merge throttle" : 0,
                                "total size of bloom filters" : 0
                        },
                        "block-manager" : {
                                "allocations requiring file extension" : 0,
                                "blocks allocated" : 0,
                                "blocks freed" : 0,
                                "checkpoint size" : 221184,
                                "file allocation unit size" : 4096,
                                "file bytes available for reuse" : 0,
                                "file magic number" : 120897,
                                "file major version number" : 1,
                                "file size in bytes" : 237568,
                                "minor version number" : 0
                        },
                        "btree" : {
                                "btree checkpoint generation" : 147,
                                "btree clean tree checkpoint expiration time" : NumberLong("9223372036854775807"),
                                "column-store fixed-size leaf pages" : 0,
                                "column-store internal pages" : 0,
                                "column-store variable-size RLE encoded values" : 0,
                                "column-store variable-size deleted values" : 0,
                                "column-store variable-size leaf pages" : 0,
                                "fixed-record size" : 0,
                                "maximum internal page key size" : 1474,
                                "maximum internal page size" : 16384,
                                "maximum leaf page key size" : 1474,
                                "maximum leaf page size" : 16384,
                                "maximum leaf page value size" : 7372,
                                "maximum tree depth" : 3,
                                "number of key/value pairs" : 0,
                                "overflow pages" : 0,
                                "pages rewritten by compaction" : 0,
                                "row-store empty values" : 0,
                                "row-store internal pages" : 0,
                                "row-store leaf pages" : 0
                        },
                        "cache" : {
                                "bytes currently in the cache" : 16504,
                                "bytes dirty in the cache cumulative" : 0,
                                "bytes read into cache" : 8010,
                                "bytes written from cache" : 0,
                                "checkpoint blocked page eviction" : 0,
                                "data source pages selected for eviction unable to be evicted" : 0,
                                "eviction walk passes of a file" : 0,
                                "eviction walk target pages histogram - 0-9" : 0,
                                "eviction walk target pages histogram - 10-31" : 0,
                                "eviction walk target pages histogram - 128 and higher" : 0,
                                "eviction walk target pages histogram - 32-63" : 0,
                                "eviction walk target pages histogram - 64-128" : 0,
                                "eviction walks abandoned" : 0,
                                "eviction walks gave up because they restarted their walk twice" : 0,
                                "eviction walks gave up because they saw too many pages and found no candidates" : 0,
                                "eviction walks gave up because they saw too many pages and found too few candidates" : 0,
                                "eviction walks reached end of tree" : 0,
                                "eviction walks started from root of tree" : 0,
                                "eviction walks started from saved location in tree" : 0,
                                "hazard pointer blocked page eviction" : 0,
                                "in-memory page passed criteria to be split" : 0,
                                "in-memory page splits" : 0,
                                "internal pages evicted" : 0,
                                "internal pages split during eviction" : 0,
                                "leaf pages split during eviction" : 0,
                                "modified pages evicted" : 0,
                                "overflow pages read into cache" : 0,
                                "page split during eviction deepened the tree" : 0,
                                "page written requiring cache overflow records" : 0,
                                "pages read into cache" : 2,
                                "pages read into cache after truncate" : 0,
                                "pages read into cache after truncate in prepare state" : 0,
                                "pages read into cache requiring cache overflow entries" : 0,
                                "pages requested from the cache" : 1,
                                "pages seen by eviction walk" : 0,
                                "pages written from cache" : 0,
                                "pages written requiring in-memory restoration" : 0,
                                "tracked dirty bytes in the cache" : 0,
                                "unmodified pages evicted" : 0
                        },
                        "cache_walk" : {
                                "Average difference between current eviction generation when the page was last considered" : 0,
                                "Average on-disk page image size seen" : 0,
                                "Average time in cache for pages that have been visited by the eviction server" : 0,
                                "Average time in cache for pages that have not been visited by the eviction server" : 0,
                                "Clean pages currently in cache" : 0,
                                "Current eviction generation" : 0,
                                "Dirty pages currently in cache" : 0,
                                "Entries in the root page" : 0,
                                "Internal pages currently in cache" : 0,
                                "Leaf pages currently in cache" : 0,
                                "Maximum difference between current eviction generation when the page was last considered" : 0,
                                "Maximum page size seen" : 0,
                                "Minimum on-disk page image size seen" : 0,
                                "Number of pages never visited by eviction server" : 0,
                                "On-disk page image sizes smaller than a single allocation unit" : 0,
                                "Pages created in memory and never written" : 0,
                                "Pages currently queued for eviction" : 0,
                                "Pages that could not be queued for eviction" : 0,
                                "Refs skipped during cache traversal" : 0,
                                "Size of the root page" : 0,
                                "Total number of pages currently in cache" : 0
                        },
                        "compression" : {
                                "compressed page maximum internal page size prior to compression" : 16384,
                                "compressed page maximum leaf page size prior to compression " : 16384,
                                "compressed pages read" : 0,
                                "compressed pages written" : 0,
                                "page written failed to compress" : 0,
                                "page written was too small to compress" : 0
                        },
                        "cursor" : {
                                "bulk loaded cursor insert calls" : 0,
                                "cache cursors reuse count" : 0,
                                "close calls that result in cache" : 0,
                                "create calls" : 1,
                                "insert calls" : 0,
                                "insert key and value bytes" : 0,
                                "modify" : 0,
                                "modify key and value bytes affected" : 0,
                                "modify value bytes modified" : 0,
                                "next calls" : 5,
                                "open cursor count" : 0,
                                "operation restarted" : 0,
                                "prev calls" : 0,
                                "remove calls" : 0,
                                "remove key bytes removed" : 0,
                                "reserve calls" : 0,
                                "reset calls" : 2,
                                "search calls" : 0,
                                "search near calls" : 1,
                                "truncate calls" : 0,
                                "update calls" : 0,
                                "update key and value bytes" : 0,
                                "update value size change" : 0
                        },
                        "reconciliation" : {
                                "dictionary matches" : 0,
                                "fast-path pages deleted" : 0,
                                "internal page key bytes discarded using suffix compression" : 0,
                                "internal page multi-block writes" : 0,
                                "internal-page overflow keys" : 0,
                                "leaf page key bytes discarded using prefix compression" : 0,
                                "leaf page multi-block writes" : 0,
                                "leaf-page overflow keys" : 0,
                                "maximum blocks required for a page" : 0,
                                "overflow values written" : 0,
                                "page checksum matches" : 0,
                                "page reconciliation calls" : 0,
                                "page reconciliation calls for eviction" : 0,
                                "pages deleted" : 0
                        },
                        "session" : {
                                "object compaction" : 0
                        },
                        "transaction" : {
                                "update conflicts" : 0
                        }
                }
        },
        "indexBuilds" : [ ],
        "totalIndexSize" : 434176,
        "indexSizes" : {
                "_id_" : 196608,
                "num_1" : 237568
        },
        "scaleFactor" : 1,
        "ok" : 1
}
>

2.4 Getting help

> db.numbers.get
db.numbers.getCollection(          db.numbers.getIndexKeys(           db.numbers.getIndices(             db.numbers.getPlanCache(           db.numbers.getShardDistribution(   db.numbers.getSplitKeysForChunks(
db.numbers.getDB(                  db.numbers.getIndexSpecs(          db.numbers.getMongo(               db.numbers.getQueryOptions(        db.numbers.getShardVersion(        db.numbers.getWriteConcern(
db.numbers.getFullName(            db.numbers.getIndexes(             db.numbers.getName(                db.numbers.getSecondaryOk(         db.numbers.getSlaveOk(
>
>
> db.numbers.save({num: 123123123})
WriteResult({ "nInserted" : 1 })
> db.numbers.save
function(obj, opts) {
    if (obj == null)
        throw Error("can't save a null");

    if (typeof (obj) == "number" || typeof (obj) == "string")
        throw Error("can't save a number or string");

    if (typeof (obj._id) == "undefined") {
        obj._id = new ObjectId();
        return this.insert(obj, opts);
    } else {
        return this.update({_id: obj._id}, obj, Object.merge({upsert: true}, opts));
    }
}
>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值