818
MongoDB Reference Manual Release 2.4.4 MongoDB Documentation Project June 20, 2013

MongoDB Reference Manual - no-SQL architecture

Embed Size (px)

DESCRIPTION

Explains about the usage of Mongo-DB, a no-SQL technology that emerging now.

Citation preview

  • MongoDB Reference ManualRelease 2.4.4

    MongoDB Documentation Project

    June 20, 2013

  • Contents

    I About MongoDB Documentation 3

    1 License 7

    2 Editions 9

    3 Version and Revisions 11

    4 Report an Issue or Make a Change Request 13

    5 Contribute to the Documentation 155.1 MongoDB Manual Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155.2 About the Documentation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    II Interfaces Reference 31

    6 mongo Shell Reference 336.1 Date() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336.2 Mongo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336.3 Mongo.getDB() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336.4 Mongo.getReadPrefMode() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346.5 Mongo.getReadPrefTagSet() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346.6 Mongo.setReadPref() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356.7 mongo.setSlaveOk() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356.8 ObjectId.getTimestamp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366.9 ObjectId.toString() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366.10 ObjectId.valueOf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366.11 UUID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376.12 cat() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376.13 cd() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.14 clearRawMongoProgramOutput() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.15 connect() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.16 copyDbpath() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.17 cursor.addOption() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.18 cursor.batchSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.19 cursor.count() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.20 cursor.explain() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406.21 cursor.forEach() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456.22 cursor.hasNext() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    i

  • 6.23 cursor.hint() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466.24 cursor.limit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466.25 cursor.map() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466.26 cursor.max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.27 cursor.min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486.28 cursor.next() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.29 cursor.objsLeftInBatch() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.30 cursor.readPref() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.31 cursor.showDiskLoc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.32 cursor.size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516.33 cursor.skip() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516.34 cursor.snapshot() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516.35 cursor.sort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526.36 cursor.toArray() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536.37 db.addUser() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536.38 db.auth() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556.39 db.changeUserPassword() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556.40 db.cloneCollection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566.41 db.cloneDatabase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566.42 db.collection.aggregate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566.43 db.collection.count() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576.44 db.collection.createIndex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.45 db.collection.dataSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.46 db.collection.distinct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.47 db.collection.drop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596.48 db.collection.dropIndex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596.49 db.collection.dropIndexes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606.50 db.collection.ensureIndex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606.51 db.collection.find() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636.52 db.collection.findAndModify() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656.53 db.collection.findOne() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686.54 db.collection.getIndexStats() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696.55 db.collection.getIndexes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696.56 db.collection.getShardDistribution() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706.57 db.collection.getShardVersion() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716.58 db.collection.group() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726.59 db.collection.indexStats() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756.60 db.collection.insert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766.61 db.collection.isCapped() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776.62 db.collection.mapReduce() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776.63 db.collection.reIndex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846.64 db.collection.remove() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856.65 db.collection.renameCollection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.66 db.collection.save() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.67 db.collection.stats() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876.68 db.collection.storageSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.69 db.collection.totalIndexSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.70 db.collection.totalSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.71 db.collection.update() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.72 db.collection.validate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.73 db.commandHelp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.74 db.copyDatabase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.75 db.createCollection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926.76 db.currentOp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

    ii

  • 6.77 db.dropDatabase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976.78 db.eval() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976.79 db.fsyncLock() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996.80 db.fsyncUnlock() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996.81 db.getCollection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.82 db.getCollectionNames() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.83 db.getLastError() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.84 db.getLastErrorObj() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.85 db.getMongo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.86 db.getName() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.87 db.getPrevError() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.88 db.getProfilingLevel() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.89 db.getProfilingStatus() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.90 db.getReplicationInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.91 db.getSiblingDB() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026.92 db.help() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036.93 db.hostInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036.94 db.isMaster() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.95 db.killOp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.96 db.listCommands() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.97 db.loadServerScripts() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.98 db.logout() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.99 db.printCollectionStats() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.100 db.printReplicationInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.101 db.printShardingStatus() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.102 db.printSlaveReplicationInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.103 db.removeUser() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.104 db.repairDatabase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.105 db.resetError() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.106 db.runCommand() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.107 db.serverBuildInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.108 db.serverStatus() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086.109 db.setProfilingLevel() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086.110 db.shutdownServer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.111 db.stats() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.112 db.version() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.113 fuzzFile() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.114 getHostName() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.115 getMemInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106.116 hostname() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106.117 _isWindows() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106.118 Collection Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106.119 Connection Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1446.120 Object Constructors and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1476.121 Cursor Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1496.122 Database Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1646.123 Native Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1866.124 Replication Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1906.125 Sharding Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1966.126 Subprocess Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2106.127 listFiles() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2116.128 load() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2116.129 ls() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2126.130 md5sumFile() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

    iii

  • 6.131 mkdir() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2126.132 pwd() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2126.133 quit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.134 rand() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.135 rawMongoProgramOutput() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.136 removeFile() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.137 resetDbpath() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.138 rs.add() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2136.139 rs.addArb() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2146.140 rs.conf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2146.141 rs.freeze() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156.142 rs.help() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156.143 rs.initiate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156.144 rs.reconfig() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156.145 rs.remove() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2166.146 rs.slaveOk() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2176.147 rs.status() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2176.148 rs.stepDown() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2176.149 rs.syncFrom() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2176.150 run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.151 runMongoProgram() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.152 runProgram() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.153 sh._adminCommand() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.154 sh._checkFullName() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.155 sh._checkMongos() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186.156 sh._lastMigration() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2196.157 sh.addShard() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2196.158 sh.addShardTag() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2206.159 sh.addTagRange() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2216.160 sh.disableBalancing() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2216.161 sh.enableBalancing() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2226.162 sh.enableSharding() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2226.163 sh.getBalancerHost() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2226.164 sh.getBalancerState() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2236.165 sh.help() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2236.166 sh.isBalancerRunning() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2236.167 sh.moveChunk() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2246.168 sh.removeShardTag() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2246.169 sh.setBalancerState() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2256.170 sh.shardCollection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2256.171 sh.splitAt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2266.172 sh.splitFind() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2266.173 sh.startBalancer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2266.174 sh.status() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2276.175 sh.stopBalancer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2296.176 sh.waitForBalancer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2306.177 sh.waitForBalancerOff() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2306.178 sh.waitForDLock() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.179 sh.waitForPingChange() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.180 _srand() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.181 startMongoProgram() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.182 stopMongoProgram() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2326.183 stopMongoProgramByPid() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2326.184 stopMongod() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

    iv

  • 6.185 version() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2326.186 waitMongoProgramOnPort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2326.187 waitProgram() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

    7 Database Command Reference 2337.1 addShard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2337.2 aggregate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2347.3 applyOps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2357.4 authenticate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2357.5 availableQueryOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2367.6 buildInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2367.7 captrunc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2377.8 checkShardingIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2387.9 clean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2387.10 clone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2387.11 cloneCollection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2387.12 cloneCollectionAsCapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2397.13 closeAllDatabases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2407.14 collMod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2407.15 collStats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2417.16 compact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2447.17 configureFailPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2467.18 connPoolStats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2477.19 connPoolSync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2497.20 convertToCapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2497.21 copydb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2507.22 copydbgetnonce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2517.23 count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2517.24 create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2527.25 cursorInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2537.26 dataSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2537.27 dbHash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2537.28 dbStats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2547.29 diagLogging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2557.30 distinct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2557.31 driverOIDTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2567.32 drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2567.33 dropDatabase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2577.34 dropIndexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2577.35 emptycapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2577.36 enableSharding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2587.37 eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2587.38 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2607.39 filemd5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2607.40 findAndModify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2607.41 flushRouterConfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2657.42 forceerror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2667.43 fsync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2667.44 geoNear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2677.45 geoSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2687.46 geoWalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2687.47 getCmdLineOpts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2697.48 getLastError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2697.49 getLog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

    v

  • 7.50 getParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2717.51 getPrevError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2717.52 getShardMap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2717.53 getShardVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2727.54 getnonce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2727.55 getoptime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2727.56 godinsert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2727.57 group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2727.58 handshake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2777.59 _hashBSONElement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2777.60 hostInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2787.61 indexStats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2807.62 isMaster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2857.63 isSelf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2877.64 isdbgrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2877.65 journalLatencyTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2887.66 listCommands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2887.67 listDatabases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2887.68 listShards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2897.69 logRotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2897.70 logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2897.71 mapReduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2907.72 mapreduce.shardedfinish . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2987.73 medianKey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2987.74 migrateClone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2987.75 moveChunk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2987.76 movePrimary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2997.77 Administration Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3007.78 Aggregation Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3167.79 Authentication Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3337.80 Query and Write Operation Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3347.81 Diagnostic Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3487.82 Geospatial Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3877.83 Internal Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3897.84 Replication Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3927.85 Sharding Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4017.86 Testing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4107.87 netstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4157.88 ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4157.89 profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4157.90 reIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4167.91 recvChunkAbort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4177.92 recvChunkCommit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4177.93 recvChunkStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4177.94 recvChunkStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4177.95 removeShard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4177.96 renameCollection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4187.97 repairDatabase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4197.98 replSetElect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4207.99 replSetFreeze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4207.100 replSetFresh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4207.101 replSetGetRBID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4207.102 replSetGetStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4217.103 replSetHeartbeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423

    vi

  • 7.104 replSetInitiate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4237.105 replSetMaintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4247.106 replSetReconfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4247.107 replSetStepDown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4257.108 replSetSyncFrom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4257.109 replSetTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4267.110 resetError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4267.111 resync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4267.112 serverStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4277.113 setParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4447.114 setShardVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4447.115 shardCollection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4447.116 shardingState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4457.117 shutdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4467.118 skewClockCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4477.119 sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4477.120 split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4477.121 splitChunk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4497.122 splitVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4507.123 testDistLockWithSkew . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4507.124 testDistLockWithSyncCluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4507.125 text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4507.126 top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4557.127 touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4567.128 transferMods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4567.129 unsetSharding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4567.130 validate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4577.131 whatsmyuri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4597.132 writeBacksQueued . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4597.133 writebacklisten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460

    8 Query, Update, Projection, and Meta-Query Operators 4618.1 $addToSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4618.2 $all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4618.3 $and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4628.4 $bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4638.5 $box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4638.6 $center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4648.7 $centerSphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4658.8 $comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4658.9 $each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4658.10 $elemMatch (query) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4668.11 $exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4668.12 $explain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4678.13 $geoIntersects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4688.14 $geoWithin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4698.15 $geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4708.16 $gt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4708.17 $gte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4718.18 $hint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4718.19 $in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4728.20 $inc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4728.21 $isolated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4738.22 $lt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473

    vii

  • 8.23 $lte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4748.24 $max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4748.25 $maxDistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4758.26 $maxScan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4758.27 $min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4758.28 $mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4768.29 $natural . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4778.30 $ne . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4778.31 $near . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4788.32 $nearSphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4798.33 $nin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4808.34 $nor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4808.35 $not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4818.36 $or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4828.37 $orderby . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4838.38 $polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4848.39 $pop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4848.40 $ (query) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4858.41 Projection Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4868.42 $pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4908.43 $pullAll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4918.44 $push . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4918.45 $pushAll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4938.46 $query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4938.47 Query Operator Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4938.48 Comparison Query Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4958.49 Element Query Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4998.50 Geospatial Query Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5028.51 JavaScript Query Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5088.52 Logical Query Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5108.53 Query Modification Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5148.54 $regex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5208.55 $rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5218.56 $returnKey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5248.57 $set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5248.58 $setOnInsert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5248.59 $showDiskLoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5258.60 $size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5268.61 $slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5268.62 $snapshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5278.63 $sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5278.64 $type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5288.65 $uniqueDocs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5308.66 $unset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5308.67 Array Update Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5318.68 Bitwise Update Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5388.69 Field Update Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5388.70 Isolation Update Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5438.71 $where . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544

    9 Aggregation Framework Operators 5479.1 Aggregation Framework Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547

    viii

  • III MongoDB and SQL Interface Comparisons 583

    10 SQL to MongoDB Mapping Chart 58510.1 Executables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58510.2 Terminology and Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58510.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

    11 SQL to Aggregation Framework Mapping Chart 59111.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591

    IV Status, Monitoring, and Reporting Output 595

    12 serverStatus 59712.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59712.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597

    13 dbStats 61513.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61513.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615

    14 connPoolStats 61714.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61714.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617

    15 collStats 62115.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62115.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62215.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623

    16 replSetGetStatus 62516.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62516.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625

    17 Exit Codes and Statuses 629

    18 db.currentOp() 63118.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63118.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63218.3 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633

    V Program and Tool Reference Pages 637

    19 MongoDB Package Components 63919.1 Core Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63919.2 Windows Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65819.3 Binary Import and Export Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66119.4 Data Import and Export Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67319.5 Diagnostic Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68019.6 GridFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69219.7 Run Time Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

    ix

  • VI Internal Metadata 715

    20 Config Database 71720.1 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717

    21 The local Database 72321.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72321.2 Collection on all mongod Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72321.3 Collections on Replica Set Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72421.4 Collections used in Master/Slave Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725

    22 System Collections 72722.1 Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72722.2 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727

    VII General System Reference 729

    23 MongoDB Limits and Thresholds 73123.1 Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73123.2 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731

    24 Glossary 735

    VIII Release Notes 747

    25 Current Stable Release 75125.1 Release Notes for MongoDB 2.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751

    26 Previous Stable Releases 77326.1 Release Notes for MongoDB 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77326.2 Release Notes for MongoDB 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78326.3 Release Notes for MongoDB 1.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78826.4 Release Notes for MongoDB 1.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79426.5 Release Notes for MongoDB 1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79626.6 Release Notes for MongoDB 1.2.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798

    27 Current Development Series 80127.1 Release Notes for MongoDB 2.6 (Development Series 2.5.x) . . . . . . . . . . . . . . . . . . . . . . 801

    28 Other MongoDB Release Notes 80528.1 Default Write Concern Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805

    x

  • MongoDB Reference Manual, Release 2.4.4

    This document contains all of the reference material from the MongoDB Manual, reflecting the 2.4.4 release. Seethe full manual, for complete documentation of MongoDB, its operation, and use.

    Contents 1

  • MongoDB Reference Manual, Release 2.4.4

    2 Contents

  • Part I

    About MongoDB Documentation

    3

  • MongoDB Reference Manual, Release 2.4.4

    The MongoDB Manual contains comprehensive documentation on the MongoDB document-oriented database man-agement system. This page describes the manuals licensing, editions, and versions, and describes how to make achange request and how to contribute to the manual.

    For more information on MongoDB, see MongoDB: A Document Oriented Database. To download MongoDB, seethe downloads page.

    5

  • MongoDB Reference Manual, Release 2.4.4

    6

  • CHAPTER 1

    License

    This manual is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (i.e.CC-BY-NC-SA) license.

    The MongoDB Manual is copyright 2011-2013 10gen, Inc.

    7

  • MongoDB Reference Manual, Release 2.4.4

    8 Chapter 1. License

  • CHAPTER 2

    Editions

    In addition to the MongoDB Manual, you can also access this content in the following editions:

    ePub Format

    Single HTML Page

    PDF Format

    You also can access PDF files that contain subsets of the MongoDB Manual:

    MongoDB Reference Manual

    MongoDB Use Case Guide

    MongoDB CRUD Operation Introduction

    For Emacs users Info/Texinfo users, the following experimental Texinfo manuals are available for offline use:

    MongoDB Manual Texinfo (tar.gz)

    MongoDB Reference Manual (tar.gz)

    MongoDB CRUD Operation Introduction (tar.gz)

    Important: The texinfo manuals are experimental. If you find an issue with one of these editions, please file anissue in the DOCS Jira project.

    9

  • MongoDB Reference Manual, Release 2.4.4

    10 Chapter 2. Editions

  • CHAPTER 3

    Version and Revisions

    This version of the manual reflects version 2.4 of MongoDB.

    See the MongoDB Documentation Project Page for an overview of all editions and output formats of the MongoDBManual. You can see the full revision history and track ongoing improvements and additions for all versions of themanual from its GitHub repository.

    This edition reflects master branch of the documentation as of the7942b52dbf0c8826477ce9937eb63a39acec8379 revision. This branch is explicitly accessible viahttp://docs.mongodb.org/master and you can always reference the commit of the current manual in the release.txtfile.

    The most up-to-date, current, and stable version of the manual is always available athttp://docs.mongodb.org/manual/.

    11

  • MongoDB Reference Manual, Release 2.4.4

    12 Chapter 3. Version and Revisions

  • CHAPTER 4

    Report an Issue or Make a Change Request

    To report an issue with this manual or to make a change request, file a ticket at the MongoDB DOCS Project on Jira.

    13

  • MongoDB Reference Manual, Release 2.4.4

    14 Chapter 4. Report an Issue or Make a Change Request

  • CHAPTER 5

    Contribute to the Documentation

    5.1 MongoDB Manual Translation

    The original authorship language for all MongoDB documentation is American English. However, ensuring thatspeakers of other languages can read and understand the documentation is of critical importance to the documentationproject.

    In this direction, the MongoDB Documentation project uses the service provided by Smartling to translate the Mon-goDB documentation into additional non-English languages. This translation project is largely supported by the workof volunteer translators from the MongoDB community who contribute to the translation effort.

    If you would like to volunteer to help translate the MongoDB documentation, please:

    complete the 10gen/MongoDB Contributor Agreement, and

    create an account on Smartling at translate.docs.mongodb.org.

    Please use the same email address you use to sign the contributor as you use to create your Smartling account.

    The mongodb-translators user group exists to facilitate collaboration between translators and the documentation teamat large. You can join the Google Group without signing the contributors agreement.

    We currently have the following languages configured:

    Arabic

    Chinese

    Czech

    French

    German

    Hungarian

    Indonesian

    Italian

    Japanese

    Korean

    Lithuanian

    Polish

    Portuguese

    15

  • MongoDB Reference Manual, Release 2.4.4

    Romanian

    Russian

    Spanish

    Turkish

    Ukrainian

    If you would like to initiate a translation project to an additional language, please report this issue using the Report aProblem link above or by posting to the mongodb-translators list.

    Currently the translation project only publishes rendered translation. While the translation effort is currently focusedon the web site we are evaluating how to retrieve the translated phrases for use in other media.

    See also:

    Contribute to the Documentation (page 15)

    MongoDB Documentation Style and Conventions (page 16)

    MongoDB Documentation Organization (page 24)

    MongoDB Documentation Practices and Processes (page 20)

    Build and Deploy the MongoDB Documentation (page 25)

    The entire documentation source for this manual is available in the mongodb/docs repository, which is one of theMongoDB project repositories on GitHub.

    To contribute to the documentation, you can open a GitHub account, fork the mongodb/docs repository, make a change,and issue a pull request.

    In order for the documentation team to accept your change, you must complete the MongoDB/10gen ContributorAgreement.

    You can clone the repository by issuing the following command at your system shell:

    git clone git://github.com/mongodb/docs.git

    5.2 About the Documentation Process

    The MongoDB Manual uses Sphinx, a sophisticated documentation engine built upon Python Docutils. The originalreStructured Text files, as well as all necessary Sphinx extensions and build tools, are available in the same repositoryas the documentation.

    For more information on the MongoDB documentation process, see:

    5.2.1 MongoDB Documentation Style and Conventions

    This document provides an overview of the style for the MongoDB documentation stored in this repository. Theoverarching goal of this style guide is to provide an accessible base style to ensure that our documentation is easy toread, simple to use, and straightforward to maintain.

    For information regarding the MongoDB Manual organization, see MongoDB Documentation Organization (page 24).

    16 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    Document History

    2011-09-27: Document created with a (very) rough list of style guidelines, conventions, and questions.

    2012-01-12: Document revised based on slight shifts in practice, and as part of an effort of making it easier for peopleoutside of the documentation team to contribute to documentation.

    2012-03-21: Merged in content from the Jargon, and cleaned up style in light of recent experiences.

    2012-08-10: Addition to the Referencing section.

    2013-02-07: Migrated this document to the manual. Added map-reduce terminology convention. Other edits.

    Naming Conventions

    This section contains guidelines on naming files, sections, documents and other document elements.

    File naming Convention:

    For Sphinx, all files should have a .txt extension.

    Separate words in file names with hyphens (i.e. -.)

    For most documents, file names should have a terse one or two word name that describes the mate-rial covered in the document. Allow the path of the file within the document tree to add some ofthe required context/categorization. For example its acceptable to have /core/sharding.rst and/administration/sharding.rst.

    For tutorials, the full title of the document should be in the file name. For example,/tutorial/replace-one-configuration-server-in-a-shard-cluster.rst

    Phrase headlines and titles so that they the content contained within the section so that users can determine whatquestions the text will answer, and material that it will address without needing them to read the content. Thisshortens the amount of time that people spend looking for answers, and improvise search/scanning, and possiblySEO.

    Prefer titles and headers in the form of Using foo over How to Foo.

    When using target references (i.e. :ref: references in documents,) use names that include enough context tobe intelligible thought all documentations. For example, use replica-set-secondary-only-nodeas opposed to secondary-only-node. This is to make the source more usable and easier to maintain.

    Style Guide

    This includes the local typesetting, English, grammatical, conventions and preferences that all documents in the manualshould use. The goal here is to choose good standards, that are clear, and have a stylistic minimalism that does notinterfere with or distract from the content. A uniform style will improve user experience, and minimize the effect of amulti-authored document.

    Punctuation

    Use the oxford comma.

    Oxford commas are the commas in a list of things (e.g. something, something else, and another thing) beforethe conjunction (e.g. and or or.).

    Do not add two spaces after terminal punctuation, such as periods.

    Place commas and periods inside quotation marks.

    5.2. About the Documentation Process 17

  • MongoDB Reference Manual, Release 2.4.4

    Use title case for headings and document titles. Title case capitalizes the first letter of the first, last, and allsignificant words.

    Verbs

    Verb tense and mood preferences, with examples:

    Avoid the first person. For example do not say, We will begin the backup process by locking the database, orI begin the backup process by locking my database instance,

    Use the second person. If you need to back up your database, start by locking the database first. In practice,however, its more concise to imply second person using the imperative, as in Before initiating a backup, lockthe database.

    When indicated, use the imperative mood. For example: Backup your databases often and To prevent dataloss, back up your databases.

    The future perfect is also useful in some cases. For example, Creating disk snapshots without locking thedatabase will lead to an inconsistent state.

    Avoid helper verbs, as possible, to increase clarity and concision. For example, attempt to avoid this doesfoo and this will do foo when possible. Use does foo over will do foo in situations where this foos isunacceptable.

    Referencing

    To refer to future or planned functionality in MongoDB or a driver, always link to the Jira case. The Manualsconf.py provides an :issue: role that links directly to a Jira case (e.g. :issue:\SERVER-9001\).

    For non-object references (i.e. functions, operators, methods, database commands, settings) always referenceonly the first occurrence of the reference in a section. You should always reference objects, except in sectionheadings.

    Structure references with the why first; the link second.

    For example, instead of this:

    Use the /tutorial/convert-replica-set-to-replicated-shard-cluster procedure if youhave an existing replica set.

    Type this:

    To deploy a sharded cluster for an existing replica set, see /tutorial/convert-replica-set-to-replicated-shard-cluster.

    General Formulations

    Contractions are acceptable insofar as they are necessary to increase readability and flow. Avoid otherwise.

    Make lists grammatically correct.

    Do not use a period after every item unless the list item completes the unfinished sentence before the list.

    Use appropriate commas and conjunctions in the list items.

    Typically begin a bulleted list with an introductory sentence or clause, with a colon or comma.

    The following terms are one word:

    standalone

    18 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    workflow

    Use unavailable, offline, or unreachable to refer to a mongod instance that cannot be accessed. Do notuse the colloquialism down.

    Always write out units (e.g. megabytes) rather than using abbreviations (e.g. MB.)

    Structural Formulations

    There should be at least two headings at every nesting level. Within an h2 block, there should be either: noh3 blocks, 2 h3 blocks, or more than 2 h3 blocks.

    Section headers are in title case (capitalize first, last, and all important words) and should effectively describethe contents of the section. In a single document you should strive to have section titles that are not redundantand grammatically consistent with each other.

    Use paragraphs and paragraph breaks to increase clarity and flow. Avoid burying critical information in themiddle of long paragraphs. Err on the side of shorter paragraphs.

    Prefer shorter sentences to longer sentences. Use complex formations only as a last resort, if at all (e.g. com-pound complex structures that require semi-colons).

    Avoid paragraphs that consist of single sentences as they often represent a sentence that has unintentionallybecome too complex or incomplete. However, sometimes such paragraphs are useful for emphasis, summary,or introductions.

    As a corollary, most sections should have multiple paragraphs.

    For longer lists and more complex lists, use bulleted items rather than integrating them inline into a sentence.

    Do not expect that the content of any example (inline or blocked,) will be self explanatory. Even when it feelsredundant, make sure that the function and use of every example is clearly described.

    ReStructured Text and Typesetting

    Place spaces between nested parentheticals and elements in JavaScript examples. For example, prefer { [ a,a, a ] } over {[a,a,a]}.

    For underlines associated with headers in RST, use:

    = for heading level 1 or h1s. Use underlines and overlines for document titles.

    - for heading level 2 or h2s.

    ~ for heading level 3 or h3s.

    for heading level 4 or h4s.

    Use hyphens (-) to indicate items of an ordered list.

    Place footnotes and other references, if you use them, at the end of a section rather than the end of a file.

    Use the footnote format that includes automatic numbering and a target name for ease of use. For instance afootnote tag may look like: [#note]_ with the corresponding directive holding the body of the footnote thatresembles the following: .. [#note].

    Do not include .. code-block:: [language] in footnotes.

    As it makes sense, use the .. code-block:: [language] form to insert literal blocks into the text.While the double colon, ::, is functional, the .. code-block:: [language] form makes the sourceeasier to read and understand.

    5.2. About the Documentation Process 19

  • MongoDB Reference Manual, Release 2.4.4

    For all mentions of referenced types (i.e. commands, operators, expressions, functions, statuses, etc.) use thereference types to ensure uniform formatting and cross-referencing.

    Jargon and Common Terms

    Database Systems and Processes

    To indicate the entire database system, use MongoDB, not mongo or Mongo.

    To indicate the database process or a server instance, use mongod or mongos. Refer to these as processesor instances. Reserve database for referring to a database structure, i.e., the structure that holds collectionsand refers to a group of files on disk.

    Distributed System Terms

    Refer to partitioned systems as sharded clusters. Do not use shard clusters or sharded systems.

    Refer to configurations that run with replication as replica sets (or master/slave deployments) rather thanclusters or other variants.

    Data Structure Terms

    document refers to rows or records in a MongoDB database. Potential confusion with JSON Docu-ments.

    Do not refer to documents as objects, because drivers (and MongoDB) do not preserve the order of fields whenfetching data. If the order of objects matter, use an array.

    field refers to a key or identifier of data within a MongoDB document.

    value refers to the contents of a field.

    sub-document describes a nested document.

    Other Terms

    Use example.net (and .org or .com if needed) for all examples and samples.

    Hyphenate map-reduce in order to avoid ambiguous reference to the command name. Do not camel-case.

    Notes on Specific Features

    Geo-Location

    1. While MongoDB is capable of storing coordinates in sub-documents, in practice, users should only storecoordinates in arrays. (See: DOCS-41.)

    5.2.2 MongoDB Documentation Practices and Processes

    This document provides an overview of the practices and processes.

    20 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    Contents

    MongoDB Documentation Practices and Processes (page 20) Commits (page 21) Standards and Practices (page 21) Collaboration (page 21) Builds (page 21) Publication (page 22) Branches (page 22) Migration from Legacy Documentation (page 22) Review Process (page 23)

    * Types of Review (page 23) Initial Technical Review (page 23) Content Review (page 23) Consistency Review (page 23) Subsequent Technical Review (page 23)

    * Review Methods (page 23)

    Commits

    When relevant, include a Jira case identifier in a commit message. Reference documentation cases when applicable,but feel free to reference other cases from jira.mongodb.org.

    Err on the side of creating a larger number of discrete commits rather than bundling large set of changes into onecommit.

    For the sake of consistency, remove trailing whitespaces in the source file.

    Hard wrap files to between 72 and 80 characters per-line.

    Standards and Practices

    At least two people should vet all non-trivial changes to the documentation before publication. One of thereviewers should have significant technical experience with the material covered in the documentation.

    All development and editorial work should transpire on GitHub branches or forks that editors can then mergeinto the publication branches.

    Collaboration

    To propose a change to the documentation, do either of the following:

    Open a ticket in the documentation project proposing the change. Someone on the documentation team willmake the change and be in contact with you so that you can review the change.

    Using GitHub, fork the mongodb/docs repository, commit your changes, and issue a pull request. Someone onthe documentation team will review and incorporate your change into the documentation.

    Builds

    Building the documentation is useful because Sphinx and docutils can catch numerous errors in the format and syntaxof the documentation. Additionally, having access to an example documentation as it will appear to the users is

    5.2. About the Documentation Process 21

  • MongoDB Reference Manual, Release 2.4.4

    useful for providing more effective basis for the review process. Besides Sphinx, Pygments, and Python-Docutils, thedocumentation repository contains all requirements for building the documentation resource.

    Talk to someone on the documentation team if you are having problems running builds yourself.

    Publication

    The makefile for this repository contains targets that automate the publication process. Use make html to publisha test build of the documentation in the build/ directory of your repository. Use make publish to build the fullcontents of the manual from the current branch in the ../public-docs/ directory relative the docs repository.

    Other targets include:

    man - builds UNIX Manual pages for all Mongodb utilities.

    push - builds and deploys the contents of the ../public-docs/.

    pdfs - builds a PDF version of the manual (requires LaTeX dependencies.)

    Branches

    This section provides an overview of the git branches in the MongoDB documentation repository and their use.

    At the present time, future work transpires in the master, with the main publication being current. As thedocumentation stabilizes, the documentation team will begin to maintain branches of the documentation for specificMongoDB releases.

    Migration from Legacy Documentation

    The MongoDB.org Wiki contains a wealth of information. As the transition to the Manual (i.e. this project andresource) continues, its critical that no information disappears or goes missing. The following process outlines howto migrate a wiki page to the manual:

    1. Read the relevant sections of the Manual, and see what the new documentation has to offer on a specific topic.

    In this process you should follow cross references and gain an understanding of both the underlying informationand how the parts of the new content relates its constituent parts.

    2. Read the wiki page you wish to redirect, and take note of all of the factual assertions, examples presented by thewiki page.

    3. Test the factual assertions of the wiki page to the greatest extent possible. Ensure that example output is accurate.In the case of commands and reference material, make sure that documented options are accurate.

    4. Make corrections to the manual page or pages to reflect any missing pieces of information.

    The target of the redirect need not contain every piece of information on the wiki page, if the manual as awhole does, and relevant section(s) with the information from the wiki page are accessible from the target of theredirection.

    5. As necessary, get these changes reviewed by another writer and/or someone familiar with the area of the infor-mation in question.

    At this point, update the relevant Jira case with the target that youve chosen for the redirect, and make the ticketunassigned.

    6. When someone has reviewed the changes and published those changes to Manual, you, or preferably someoneelse on the team, should make a final pass at both pages with fresh eyes and then make the redirect.

    22 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    Steps 1-5 should ensure that no information is lost in the migration, and that the final review in step 6 should betrivial to complete.

    Review Process

    Types of Review

    The content in the Manual undergoes many types of review, including the following:

    Initial Technical Review Review by an engineer familiar with MongoDB and the topic area of the documentation.This review focuses on technical content, and correctness of the procedures and facts presented, but can improve anyaspect of the documentation that may still be lacking. When both the initial technical review and the content revieware complete, the piece may be published.

    Content Review Textual review by another writer to ensure stylistic consistency with the rest of the manual. De-pending on the content, this may precede or follow the initial technical review. When both the initial technical reviewand the content review are complete, the piece may be published.

    Consistency Review This occurs post-publication and is content focused. The goals of consistency reviews are toincrease the internal consistency of the documentation as a whole. Insert relevant cross-references, update the style asneeded, and provide background fact-checking.

    When possible, consistency reviews should be as systematic as possible and we should avoid encouraging stylistic andinformation drift by editing only small sections at a time.

    Subsequent Technical Review If the documentation needs to be updated following a change in functionality of theserver or following the resolution of a user issue, changes may be significant enough to warrant additional technicalreview. These reviews follow the same form as the initial technical review, but is often less involved and covers asmaller area.

    Review Methods

    If youre not a usual contributor to the documentation and would like to review something, you can submit reviews inany of the following methods:

    If youre reviewing an open pull request in GitHub, the best way to comment is on the overview diff, whichyou can find by clicking on the diff button in the upper left portion of the screen. You can also use thefollowing URL to reach this interface:

    https://github.com/mongodb/docs/pull/[pull-request-id]/files

    Replace [pull-request-id] with the identifier of the pull request. Make all comments inline, usingGitHubs comment system.

    You may also provide comments directly on commits, or on the pull request itself but these commit-commentsare archived in less coherent ways and generate less useful emails, while comments on the pull request lead toless specific changes to the document.

    Leave feedback on Jira cases in the DOCS project. These are better for more general changes that arentnecessarily tied to a specific line, or affect multiple files.

    5.2. About the Documentation Process 23

  • MongoDB Reference Manual, Release 2.4.4

    Create a fork of the repository in your GitHub account, make any required changes and then create a pull requestwith your changes.

    If you insert lines that begin with any of the following annotations:

    .. TODO:TODO:.. TODOTODO

    followed by your comments, it will be easier for the original writer to locate your comments. The two dots ..format is a comment in reStructured Text, which will hide your comments from Sphinx and publication if youreworried about that.

    This format is often easier for reviewers with larger portions of content to review.

    5.2.3 MongoDB Documentation Organization

    This document provides an overview of the global organization of the documentation resource. Refer to the notesbelow if you are having trouble understanding the reasoning behind a files current location, or if you want to add newdocumentation but arent sure how to integrate it into the existing resource.

    If you have questions, dont hesitate to open a ticket in the Documentation Jira Project or contact the documentationteam.

    Global Organization

    Indexes and Experience

    The documentation project has two index files: /contents.txt and /index.txt. The contents file providesthe documentations tree structure, which Sphinx uses to create the left-pane navigational structure, to power theNext and Previous page functionality, and to provide all overarching outlines of the resource. The index file isnot included in the contents file (and thus builds will produce a warning here) and is the page that users first land onwhen visiting the resource.

    Having separate contents and index files provides a bit more flexibility with the organization of the resource whilealso making it possible to customize the primary user experience.

    Additionally, in the top level of the source/ directory, there are a number of topical index or outline files. These(like the index and contents files) use the .. toctree:: directive to provide organization within the docu-mentation. The subject-specific landing pages indexes combine to create the index in the contents file.

    Topical Indexes and Meta Organization

    Because the documentation on any given subject exists in a number of different locations across the resource thetopical indexes provide the real structure and organization to the resource. This organization makes it possible toprovide great flexibility while still maintaining a reasonable organization of files and URLs for the documentation.Consider the following example:

    Given that topic such as replication, has material regarding the administration of replica sets, as wellas reference material, an overview of the functionality, and operational tutorials, it makes more sense toinclude a few locations for documents, and use the meta documents to provide the topic-level organization.

    Current landing pages include:

    administration

    24 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    applications

    crud

    faq

    mongo

    reference

    replication

    security

    sharding

    Additional topical indexes are forthcoming.

    The Top Level Folders

    The documentation has a number of top-level folders, that hold all of the content of the resource. Consider thefollowing list and explanations below:

    administration - contains all of the operational and architectural information that systems and database ad-ministrators need to know in order to run MongoDB. Topics include: monitoring, replica sets, shard clusters,deployment architectures, and configuration.

    applications - contains information about application development and use. While most documentation re-garding application development is within the purview of the driver documentation, there are some larger topicsregarding the use of these features that deserve some coverage in this context. Topics include: drivers, schemadesign, optimization, replication, and sharding.

    applications/use-cases - contains use cases that detail how MongoDB can support various kinds uses andapplication designs, including in depth instructions and examples.

    core - contains overviews and introduction to the core features, functionality, and concepts of MongoDB.Topics include: replication, sharding, capped collections, journaling/durability, aggregation.

    reference - contains references and indexes of shell functions, database commands, status outputs, as well asmanual pages for all of the programs come with MongoDB (e.g. mongostat and mongodump.)

    tutorial - contains operational guides and tutorials that lead users through common tasks (administrative andconceptual) with MongoDB. This includes programming patterns and operational guides.

    faq - contains all the frequently asked questions related to MongoDB, in a collection of topical files.

    5.2.4 Build and Deploy the MongoDB Documentation

    This document contains more direct instructions for building the MongoDB documentation.

    Requirements

    For basic publication and testing:

    GNU Make

    Python

    Git

    Sphinx (documentation management toolchain)

    5.2. About the Documentation Process 25

  • MongoDB Reference Manual, Release 2.4.4

    Pygments (syntax highlighting)

    PyYAML (for the generated tables)

    For full publication builds:

    python-argparse

    LaTeX/PDF LaTeX (typically texlive; for building PDFs)

    Common Utilities (rsync, tar, gzip, sed)

    Building the Documentation

    Clone the repository:

    git clone git://github.com/mongodb/docs.git

    To build the full publication version of the manual, you will need to have a function LaTeX tool chain; however, forroutine day-to-day rendering of the documentation you can install a much more minimal tool chain.

    For Routine Builds

    Begin by installing dependencies. On Arch Linux, use the following command to install the full dependencies:

    pacman -S python2-sphinx python2-pygments python2-yaml

    On Debian/Ubuntu systems issue the following command:

    apt-get install python-sphinx python-yaml python-argparse

    To build the documentation issue the following command:

    make html

    You can find the build output in build//html, where is the name of your current branch.

    For Publication Builds

    Begin by installing additional dependencies. On Arch Linux, use the following command to install the full dependen-cies:

    pacman -S python2-sphinx python2-pygments python2-yaml \texlive-bin texlive-core texlive-latexextra

    On Debian/Ubuntu systems use the following command:

    apt-get install python-yaml python-argparse python-sphinx \texlive-latex-recommended texlive-latex-recommended

    Note: The Debian/Ubuntu dependencies, have not been thoroughly tested. If you find an additional dependency,please submit a pull request to modify this document.

    On OS X:

    1. You may need to use easy_install to install pip using the following command if you have not alreadydone so:

    26 Chapter 5. Contribute to the Documentation

  • MongoDB Reference Manual, Release 2.4.4

    easy_install pip

    Alternately, you may be able to replace pip with easy_install in the next step.

    2. Install Sphinx, Docutils, and their dependencies with pip using the following command:

    pip install Sphinx Jinja2 Pygments docutils PyYAML

    Jinja2, Pygments, and docutils are all dependencies of Sphinx.

    Note: As of June 6, 2012 and Sphinx version 1.1.3, you must compile the MongoDB documentation using thePython 2.x series version of Sphinx. There are serious generation problems with the Python 3 series version ofSphinx.

    3. Install a TeX distribution (for building the PDF.) If you do not have a LaTeX installation, use MacTeX

    If you have any corrections to the instructions for these platforms or you have a dependency list for Fedora, CentOS,Red Hat, or other related distributions, please submit a pull request to add this information to this document.

    To build a test version of the Manual, issue the following command:

    make publish

    This places a complete version of the manual in ../public-docs/ named for the current branch (as of 2012-03-19, typically master.)

    To publish a new build of the manual, issue the following command:

    make push

    Warning: This target depends on publish, and simply uses rsync to move the content of the../public-docs/ to the web servers. You must have the proper credentials to run these operations.

    Run publish procedure and thoroughly test the build before pushing it live.

    Troubleshooting

    If you encounter problems with the build, please contact the docs team, so that we can update this guide and/or fix thebuild process.

    Build Components and Internals

    This section describes the build system for the MongoDB manual, including the custom components, and the organi-zation of the production build process, and the implementation and encoding of the build process.

    Tables

    bin/table_builder.py provides a way to generate easy to main reStructuredText tables, from content stored inYAML files.

    Rationale: reStructuredTexts default tables are easy to read in source format, but expensive to maintain, particularlywith larger numbers of columns, because changing widths of column necessitates reformatting the entire table. re-StructuredText does provide a more simple list table format for simple tables, but these tables do not support morecomplex multi-line output.

    Solution: table_builder.py reads a .yaml file that contains three documents:

    5.2. About the Documentation Process 27

  • MongoDB Reference Manual, Release 2.4.4

    (Each document has a section field that holds the name/type of the section, that table_builder.py uses to ensurethat the YAML file is well formed.)

    1. A layout document that describes the structure the final presentation of the table. Contains two field, aheader that holds a list of field references, and a rows field that holds a list of lists of field references, forexample:

    section: layoutheader: [ meta.header1, meta.header2 ]rows:- 1: [ content.sql1, content.mongo1 ]- 2: [ content.sql2, content.mongo2 ]- 3: [ content.sql3, content.mongo3 ]- 4: [ content.sql4, content.mongo4 ]

    2. A meta document that holds row, column or other minor descriptions, referenced in the layout section.

    3. A content document that holds the major content of the document.

    There is no functional difference between meta and content fields except that they each provide a distinct names-pace for table content.

    table_builder.py generates .rst output files from .yaml files. The documents processed by Sphinx use the.. include:: reStructuredText directive to include the .rst file. The build system includes targets (generated,)for all tables, which are a dependency of the Sphinx build process. 1

    Use: To add a table:

    create an appropriate .yaml file using any of the existing files as an example. The build system generates alltable files in the source/includes/ directory with the .yaml extension that begin with table-.

    include the generated .rst file in your Sphinx document. (Optional.)

    Generated Makefiles

    System While the makefile in the top level of documentation source coordinates the build process, most ofthe build targets and build system exist in the form of makefiles generated by a collection of Python scripts. Thisarchitecture reduces redundancy while increasing clarity and consistency.

    These makefiles enter the build process by way of include statements and a pattern rule inbin/makefile.dynamic, as follows:

    -include $(output)/makefile.tables-include $(output)/makefile.sphinx

    $(output)/makefile.%:bin/makefile-builder/%.py bin/makefile_builder.py bin/builder_data.py@$(PYTHONBIN) bin/makefile-builder/$(subst .,,$(suffix $@)).py $@

    This will rebuild any of the include fi