[TOC]
 
- MongoDB官方文档中文版
 - MongoDB用户手册
 - MongoDB简介
 -  安装 MongoDB   
- 安装MongoDB社区版
 - 安装MongoDB企业版
 - 将社区版MongoDB升级到企业版MongoDB
 - 验证MongoDB软件包的完整性
 
 - Mongo Shell
 - 增删改查操作
 - 聚合
 -  数据模式   
- 数据建模介绍
 - 模式验证
 - Data Modeling Concepts
 -  Data Model Examples and Patterns   
- Model Relationships Between Documents
 - Model One-to-One Relationships with Embedded Documents
 - Model One-to-Many Relationships with Embedded Documents
 - Model One-to-Many Relationships with Document References
 - Model Tree Structures
 - Model Tree Structures with Parent References
 - Model Tree Structures with Child References
 - Model Tree Structures with an Array of Ancestors
 - Model Tree Structures with Materialized Paths
 - Model Tree Structures with Nested Sets
 - Model Specific Application Contexts
 - Model Data for Atomic Operations
 - Model Data to Support Keyword Search
 - Model Data for Schema Versioning
 - Model Monetary Data
 - Model Time Data
 - Model Computed Data
 
 - Data Model Reference
 
 - 事务
 -  索引   
- Single Field Indexes
 - Compound Indexes
 - Multikey Indexes
 - Text Indexes
 - Wildcard Indexes
 - 2dsphere Indexes
 - 2d Indexes
 - geoHaystack Indexes
 - Hashed Indexes
 - 索引特性
 - Index Builds on Populated Collections
 - 索引交集
 - Manage Indexes
 - 衡量索引使用
 - Indexing Strategies
 - Indexing Reference
 - 2d索引
 - 2dsphere索引
 - 复合索引
 - geoHaystack索引
 - Hashed 索引
 - 在填充的集合上建立索引
 - 索引参考
 - 索引策略
 - 管理索引
 - 多键索引
 - 单字段索引
 - 文本索引
 - 通配符索引
 
 -  安全   
- 安全检查列表
 - Enable Access Control
 -  身份验证   
- Users
 - Add Users
 - Authentication Mechanisms
 - SCRAM
 - x.509
 - Enterprise Authentication Mechanisms
 - Kerberos Authentication
 - LDAP Proxy Authentication
 - LDAP Authorization
 - Internal/Membership Authentication
 - Deploy Replica Set With Keyfile Authentication
 - Update Replica Set to Keyfile Authentication
 - Update Replica Set to Keyfile Authentication (No Downtime)
 - Rotate Keys for Replica Sets
 - Deploy Sharded Cluster with Keyfile Authentication
 - Update Sharded Cluster to Keyfile Authentication
 - Update Sharded Cluster to Keyfile Authentication (No Downtime)
 - Rotate Keys for Sharded Clusters
 - Use x.509 Certificate for Membership Authentication
 - Upgrade from Keyfile Authentication to x.509 Authentication
 - Rolling Update of x.509 Cluster Certificates that Contain New DN
 
 - Role-Based Access Control
 - TLS/SSL (Transport Encryption)
 - Encryption at Rest
 - Client-Side Field Level Encryption
 - 审计
 - Network and Configuration Hardening
 - Implement Field Level Redaction
 - Security Reference
 - Create a Vulnerability Report
 - Appendix
 - 附录
 - 启用访问控制
 - 网络和配置强化
 - 安全参考
 
 - 改变流
 -  复制集   
- 复制集成员
 - 副本集日志
 - Replica Set Data Synchronization
 - 副本集部署架构
 - Replica Set High Availability
 - Replica Set Read and Write Semantics
 - Replica Set Deployment Tutorials
 - Member Configuration Tutorials
 -  Replica Set Maintenance Tutorials   
- Change the Size of the Oplog
 - Perform Maintenance on Replica Set Members
 - Force a Member to Become Primary
 - Resync a Member of a Replica Set
 - Configure Replica Set Tag Sets
 - Reconfigure a Replica Set with Unavailable Members
 - Manage Chained Replication
 - Change Hostnames in a Replica Set
 - Configure a Secondary’s Sync Target
 
 - Replication Reference
 - 副本集数据同步
 
 -  分片   
- 分片集群组成]
 - 片键
 - 哈希分片
 - 范围分片
 - 部署分片集群
 - 区域
 - Data Partitioning with Chunks
 - Balancer
 -  Administration   
- Config Server Administration
 - Replace a Config Server
 - View Cluster Configuration
 - Restart a Sharded Cluster
 - Migrate a Sharded Cluster to Different Hardware
 - Add Shards to a Cluster
 - Remove Shards from an Existing Sharded Cluster
 - Clear jumbo Flag
 - Back Up Cluster Metadata
 - Convert Sharded Cluster to Replica Set
 - Convert a Replica Set to a Sharded Cluster
 - Convert a Shard Standalone to a Shard Replica Set
 
 - Sharding Reference
 - 分片键
 - Zone
 
 -  管理权限   
- 产品说明
 - Operations Checklist
 - Development Checklist
 - Performance
 - 配置和维护
 - Data Center Awareness
 -  MongoDB Backup Methods   
- Back Up and Restore with Filesystem Snapshots
 - Back Up and Restore with MongoDB Tools
 - Restore a Replica Set from MongoDB Backups
 - Backup and Restore Sharded Clusters
 - Back Up a Sharded Cluster with File System Snapshots
 - Back Up a Sharded Cluster with Database Dumps
 - Schedule Backup Window for Sharded Clusters
 - Restore a Sharded Cluster
 - Recover a Standalone after an Unexpected Shutdown
 
 - Monitoring for MongoDB
 - 开发检查表
 - MogoDB 备份方法
 - 操作检查表
 - MongoDB性能
 
 - 存储
 - 常见问题
 -  参考   
-  Operators   
- Query and Projection Operators
 - Comparison Query Operators
 - Logical Query Operators
 - Element Query Operators
 - Evaluation Query Operators
 - Geospatial Query Operators
 - Array Query Operators
 - Bitwise Query Operators
 - $comment
 - 查询与映射运算符
 - 更新运算符
 - Field Update Operators
 - Array Update Operators
 - Bitwise Update Operator
 - Aggregation Pipeline Stages
 - $addFields (aggregation)
 - $bucket (aggregation)
 - $bucketAuto (aggregation)
 - $collStats (aggregation)
 - $count (aggregation)
 - $currentOp (aggregation)
 - $facet (aggregation)
 - $geoNear (aggregation)
 - $graphLookup (aggregation)
 - $group (aggregation)
 - $indexStats (aggregation)
 - $limit (aggregation)
 - $listLocalSessions
 - $listSessions
 - $lookup (aggregation)
 - $match (aggregation)
 - $merge (aggregation)
 - $out (aggregation)
 - $planCacheStats
 - $project (aggregation)
 - $redact (aggregation)
 - $replaceRoot (aggregation)
 - $replaceWith (aggregation)
 - $sample (aggregation)
 - $set (aggregation)
 - $skip (aggregation)
 - $sort (aggregation)
 - $sortByCount (aggregation)
 - $unionWith (aggregation)
 - $unset (aggregation)
 - $unwind (aggregation)
 - Aggregation Pipeline Operators
 - $sin (aggregation)
 - $abs (aggregation)
 - $slice (aggregation)
 - $accumulator (aggregation)
 - $split (aggregation)
 - $acos (aggregation)
 - $sqrt (aggregation)
 - $acosh (aggregation)
 - $add (aggregation)
 - $addToSet (aggregation)
 - $allElementsTrue (aggregation)
 - $and (aggregation)
 - $anyElementTrue (aggregation)
 - $arrayElemAt (aggregation)
 - $arrayToObject (aggregation)
 - $asin (aggregation)
 - $asinh (aggregation)
 - $sum (aggregation)
 - $atan (aggregation)
 - $atan2 (aggregation)
 - $tan (aggregation)
 - $atanh (aggregation)
 - $avg (aggregation)
 - $binarySize (aggregation)
 - $bsonSize (aggregation)
 - $ceil (aggregation)
 - $toInt (aggregation)
 - $cmp (aggregation)
 - $concat (aggregation)
 - $concatArrays (aggregation)
 - $cond (aggregation)
 - $convert (aggregation)
 - $cos (aggregation)
 - $dateFromParts (aggregation)
 - $dateToParts (aggregation)
 - $type (aggregation)
 - $dateFromString (aggregation)
 - $week (aggregation)
 - $dateToString (aggregation)
 - $year (aggregation)
 - $dayOfMonth (aggregation)
 - $zip (aggregation)
 - $dayOfWeek (aggregation)
 - $dayOfYear (aggregation)
 - $degreesToRadians (aggregation)
 - $divide (aggregation)
 - $eq (aggregation)
 - $exp (aggregation)
 - $filter (aggregation)
 - $first (aggregation accumulator)
 - $first (aggregation)
 - $floor (aggregation)
 - $function (aggregation)
 - $gt (aggregation)
 - $gte (aggregation)
 - $hour (aggregation)
 - $ifNull (aggregation)
 - $in (aggregation)
 - $indexOfArray (aggregation)
 - $indexOfBytes (aggregation)
 - $indexOfCP (aggregation)
 - $isArray (aggregation)
 - $isNumber (aggregation)
 - $isoDayOfWeek (aggregation)
 - $isoWeek (aggregation)
 - $isoWeekYear (aggregation)
 - $last (aggregation accumulator)
 - $last (aggregation)
 - $let (aggregation)
 - $literal (aggregation)
 - $ln (aggregation)
 - $log (aggregation)
 - $log10 (aggregation)
 - $lt (aggregation)
 - $lte (aggregation)
 - $trim (aggregation)
 - $map (aggregation)
 - $max (aggregation)
 - $mergeObjects (aggregation)
 - $meta
 - $min (aggregation)
 - $millisecond (aggregation)
 - $minute (aggregation)
 - $mod (aggregation)
 - $month (aggregation)
 - $multiply (aggregation)
 - $ne (aggregation)
 - $not (aggregation)
 - $objectToArray (aggregation)
 - $or (aggregation)
 - $pow (aggregation)
 - $push (aggregation)
 - $radiansToDegrees (aggregation)
 - $range (aggregation)
 - $reduce (aggregation)
 - $regexFind (aggregation)
 - $regexFindAll (aggregation)
 - $regexMatch (aggregation)
 - $replaceOne (aggregation)
 - $replaceAll (aggregation)
 - $reverseArray (aggregation)
 - $round (aggregation)
 - $rtrim (aggregation)
 - $second (aggregation)
 - $setDifference (aggregation)
 - $setEquals (aggregation)
 - $setIntersection (aggregation)
 - $setIsSubset (aggregation)
 - $setUnion (aggregation)
 - $size (aggregation)
 - $slice (aggregation)
 - $split (aggregation)
 - $sqrt (aggregation)
 - $stdDevPop (aggregation)
 - $stdDevSamp (aggregation)
 - $strcasecmp (aggregation)
 - $strLenBytes (aggregation)
 - $strLenCP (aggregation)
 - $substr (aggregation)
 - $substrBytes (aggregation)
 - $substrCP (aggregation)
 - $subtract (aggregation)
 - $sum (aggregation)
 - $switch (aggregation)
 - $tan (aggregation)
 - $toBool (aggregation)
 - $toDate (aggregation)
 - $toDecimal (aggregation)
 - $toDouble(aggregation)
 - $toInt (aggregation)
 - $toLong (aggregation)
 - $toObjectId (aggregation)
 - $toString (aggregation)
 - $toLower (aggregation)
 - $toUpper (aggregation)
 - $trim (aggregation)
 - $trunc (aggregation)
 - $type (aggregation)
 - $week (aggregation)
 - $year (aggregation)
 - $zip (aggregation)
 - 查询修饰符
 - $comment
 - $explain
 - $hint
 - $max
 - $maxTimeMS
 - $min
 - $orderby
 - $query
 - $returnKey
 - $showDiskLoc
 - $natural
 - 聚合管道操作符
 - $abs (aggregation)
 - $acos (aggregation)
 - $acosh (aggregation)
 - $add (aggregation)
 - $addToSet (aggregation)
 - $and (aggregation)
 - $anyElementTrue (aggregation)
 - $arrayElemAt (aggregation)
 - $arrayToObject (aggregation)
 - $asin (aggregation)
 - $asinh (aggregation)
 - $atan (aggregation)
 - $atan2 (aggregation)
 - $atanh (aggregation)
 - $avg (aggregation)
 - $ceil (aggregation)
 - $cmp (aggregation)
 - $concat (aggregation)
 - $concatArrays (aggregation)
 - $cond (aggregation)
 - $convert (aggregation)
 - $cos (aggregation)
 - $dateFromParts (aggregation)
 - $dateFromString (aggregation)
 - $dateToParts (aggregation)
 - $dateToString (aggregation)
 - $literal (aggregation)
 - 聚合管道阶段
 
 -  数据库命令   
- Aggregation Commands
 - aggregate
 - count
 - distinct
 - mapReduce
 - Geospatial Commands
 - geoSearch
 - Query and Write Operation Commands
 - delete
 - find
 - findAndModify
 - getLastError
 - getMore
 - insert
 - resetError
 - update
 - 查询计划缓存命令
 - planCacheClear
 - planCacheClearFilters
 - planCacheListFilters
 - planCacheSetFilter
 - 认证命令
 - authenticate
 - getnonce
 - logout
 - User Management Commands
 - createUser
 - dropAllUsersFromDatabase
 - dropUser
 - grantRolesToUser
 - revokeRolesFromUser
 - updateUser
 - usersInfo
 - Role Management Commands
 - createRole
 - dropRole
 - dropAllRolesFromDatabase
 - grantPrivilegesToRole
 - grantRolesToRole
 - invalidateUserCache
 - revokePrivilegesFromRole
 - revokeRolesFromRole
 - rolesInfo
 - updateRole
 - Replication Commands
 - applyOps
 - isMaster
 - replSetAbortPrimaryCatchUp
 - replSetFreeze
 - replSetGetConfig
 - replSetGetStatus
 - replSetInitiate
 - replSetMaintenance
 - replSetReconfig
 - replSetResizeOplog
 - replSetStepDown
 - replSetSyncFrom
 - Sharding Commands
 - addShard
 - addShardToZone
 - balancerCollectionStatus
 - balancerStart
 - balancerStatus
 - balancerStop
 - checkShardingIndex
 - clearJumboFlag
 - cleanupOrphaned
 - enableSharding
 - flushRouterConfig
 - getShardMap
 - getShardVersion
 - isdbgrid
 - listShards
 - medianKey
 - moveChunk
 - movePrimary
 - mergeChunks
 - refineCollectionShardKey
 - removeShard
 - removeShardFromZone
 - setShardVersion
 - shardCollection
 - shardingState
 - split
 - splitChunk
 - splitVector
 - unsetSharding
 - updateZoneKeyRange
 - Sessions Commands
 - abortTransaction
 - commitTransaction
 - endSessions
 - killAllSessions
 - killAllSessionsByPattern
 - killSessions
 - refreshSessions
 - startSession
 - Administration Commands
 - cloneCollectionAsCapped
 - collMod
 - compact
 - connPoolSync
 - convertToCapped
 - create
 - createIndexes
 - currentOp
 - drop
 - dropDatabase
 - dropConnections
 - dropIndexes
 - filemd5
 - fsync
 - fsyncUnlock
 - getDefaultRWConcern
 - getParameter
 - killCursors
 - killOp
 - listCollections
 - listDatabases
 - listIndexes
 - logRotate
 - reIndex
 - renameCollection
 - setFeatureCompatibilityVersion
 - setIndexCommitQuorum
 - setParameter
 - setDefaultRWConcern
 - shutdown
 - Diagnostic Commands
 - availableQueryOptions
 - buildInfo
 - collStats
 - connPoolStats
 - connectionStatus
 - cursorInfo
 - dataSize
 - dbHash
 - dbStats
 - diagLogging
 - driverOIDTest
 - explain
 - features
 - getCmdLineOpts
 - getLog
 - hostInfo
 - isSelf
 - listCommands
 - lockInfo
 - netstat
 - ping
 - profile
 - serverStatus
 - shardConnPoolStats
 - top
 - validate
 - whatsmyuri
 - 免费监控命令
 - getFreeMonitoringStatus
 - setFreeMonitoring
 - 数据库命令
 - logApplicationMessage
 - 管理命令
 - 聚合命令
 - 诊断命令
 - 地理空间命令
 - 查询和写操作命令
 - 复制命令
 - 角色管理命令
 - 会话命令
 - 分片命令
 - 用户管理命令
 
 -  mongo Shell 方法   
- Collection Methods
 - db.collection.aggregate()
 - db.collection.bulkWrite()
 - db.collection.copyTo()
 - db.collection.count()
 - db.collection.countDocuments()
 - db.collection.estimatedDocumentCount()
 - db.collection.createIndex()
 - db.collection.createIndexes()
 - db.collection.dataSize()
 - db.collection.deleteOne()
 - db.collection.deleteMany()
 - db.collection.distinct()
 - db.collection.drop()
 - db.collection.dropIndex()
 - db.collection.dropIndexes()
 - db.collection.ensureIndex()
 - db.collection.explain()
 - db.collection.find()
 - db.collection.findAndModify()
 - db.collection.findOne()
 - db.collection.findOneAndDelete()
 - db.collection.findOneAndReplace()
 - db.collection.findOneAndUpdate()
 - db.collection.getIndexes()
 - db.collection.getShardDistribution()
 - db.collection.getShardVersion()
 - db.collection.hideIndex()
 - db.collection.insert()
 - db.collection.insertOne()
 - db.collection.insertMany()
 - db.collection.isCapped()
 - db.collection.latencyStats()
 - db.collection.mapReduce()
 - db.collection.reIndex()
 - db.collection.remove()
 - db.collection.renameCollection()
 - db.collection.replaceOne()
 - db.collection.save()
 - db.collection.stats()
 - db.collection.storageSize()
 - db.collection.totalIndexSize()
 - db.collection.totalSize()
 - db.collection.unhideIndex()
 - db.collection.update()
 - db.collection.updateOne()
 - db.collection.updateMany()
 - db.collection.watch()
 - db.collection.validate()
 - Cursor Methods
 - cursor.addOption()
 - cursor.allowDiskUse()
 - cursor.allowPartialResults()
 - cursor.batchSize()
 - cursor.close()
 - cursor.isClosed()
 - cursor.collation()
 - cursor.comment()
 - cursor.count()
 - cursor.explain()
 - cursor.forEach()
 - cursor.hasNext()
 - cursor.hint()
 - cursor.isExhausted()
 - cursor.itcount()
 - cursor.limit()
 - cursor.map()
 - cursor.max()
 - cursor.maxTimeMS()
 - cursor.min()
 - cursor.next()
 - cursor.noCursorTimeout()
 - cursor.objsLeftInBatch()
 - cursor.pretty()
 - cursor.readConcern()
 - cursor.readPref()
 - cursor.returnKey()
 - cursor.showRecordId()
 - cursor.size()
 - cursor.skip()
 - cursor.sort()
 - cursor.tailable()
 - cursor.toArray()
 - Database Methods
 - db.adminCommand()
 - db.aggregate()
 - db.cloneDatabase()
 - db.commandHelp()
 - db.copyDatabase()
 - db.createCollection()
 - db.createView()
 - db.currentOp()
 - db.dropDatabase()
 - db.eval()
 - db.fsyncLock()
 - db.fsyncUnlock()
 - db.getCollection()
 - db.getCollectionInfos()
 - db.getCollectionNames()
 - db.getLastError()
 - db.getLastErrorObj()
 - db.getLogComponents()
 - db.getMongo()
 - db.getName()
 - db.getProfilingLevel()
 - db.getProfilingStatus()
 - db.getReplicationInfo()
 - db.getSiblingDB()
 - db.help()
 - db.hostInfo()
 - db.isMaster()
 - db.killOp()
 - db.listCommands()
 - db.logout()
 - db.printCollectionStats()
 - db.printReplicationInfo()
 - db.printShardingStatus()
 - db.printSlaveReplicationInfo()
 - db.resetError()
 - db.runCommand()
 - db.serverBuildInfo()
 - db.serverCmdLineOpts()
 - db.serverStatus()
 - db.setLogLevel()
 - db.setProfilingLevel()
 - db.shutdownServer()
 - db.stats()
 - db.version()
 - db.watch()
 - Query Plan Cache Methods
 - db.collection.getPlanCache()
 - PlanCache.clear()
 - PlanCache.clearPlansByQuery()
 - PlanCache.help()
 - PlanCache.list()
 - Bulk Operation Methods
 - db.collection.initializeOrderedBulkOp()
 - db.collection.initializeUnorderedBulkOp()
 - Bulk()
 - Bulk.execute()
 - Bulk.find()
 - Bulk.find.arrayFilters()
 - Bulk.find.collation()
 - Bulk.find.hint()
 - Bulk.find.remove()
 - Bulk.find.removeOne()
 - Bulk.find.replaceOne()
 - Bulk.find.updateOne()
 - Bulk.find.update()
 - Bulk.find.upsert()
 - Bulk.getOperations()
 - Bulk.insert()
 - Bulk.tojson()
 - Bulk.toString()
 - User Management Methods
 - db.auth()
 - db.changeUserPassword()
 - db.createUser()
 - db.dropUser()
 - db.dropAllUsers()
 - db.getUser()
 - db.getUsers()
 - db.grantRolesToUser()
 - db.removeUser()
 - db.revokeRolesFromUser()
 - db.updateUser()
 - passwordPrompt()
 - Role Management Methods
 - db.createRole()
 - db.dropRole()
 - db.dropAllRoles()
 - db.getRole()
 - db.getRoles()
 - db.grantPrivilegesToRole()
 - db.revokePrivilegesFromRole()
 - db.grantRolesToRole()
 - db.revokeRolesFromRole()
 - db.updateRole()
 - Replication Methods
 - rs.add()
 - rs.addArb()
 - rs.conf()
 - rs.freeze()
 - rs.help()
 - rs.initiate()
 - rs.printReplicationInfo()
 - rs.printSlaveReplicationInfo()
 - rs.reconfig()
 - rs.remove()
 - rs.status()
 - rs.stepDown()
 - rs.syncFrom()
 - Sharding Methods
 - sh.addShard()
 - sh.addShardTag()
 - sh.addShardToZone()
 - sh.addTagRange()
 - sh.balancerCollectionStatus()
 - sh.disableBalancing()
 - sh.enableBalancing()
 - sh.disableAutoSplit
 - sh.enableAutoSplit
 - sh.enableSharding()
 - sh.getBalancerHost()
 - sh.getBalancerState()
 - sh.removeTagRange()
 - sh.removeRangeFromZone()
 - sh.help()
 - sh.isBalancerRunning()
 - sh.moveChunk()
 - sh.removeShardTag()
 - sh.removeShardFromZone()
 - sh.setBalancerState()
 - sh.shardCollection()
 - sh.splitAt()
 - sh.splitFind()
 - sh.startBalancer()
 - sh.status()
 - sh.stopBalancer()
 - sh.waitForBalancer()
 - sh.waitForBalancerOff()
 - sh.waitForPingChange()
 - sh.updateZoneKeyRange()
 - convertShardKeyToHashed
 - Free Monitoring Methods
 - db.disableFreeMonitoring()
 - db.enableFreeMonitoring()
 - db.getFreeMonitoringStatus
 - Object Constructors and Methods
 - BulkWriteResult()
 - Date()
 - ObjectId
 - ObjectId.getTimestamp()
 - ObjectId.toString()
 - ObjectId.valueOf()
 - UUID()
 - WriteResult()
 - WriteResult.hasWriteError()
 - WriteResult.hasWriteConcernError()
 - Connection Methods
 - connect()
 - Mongo()
 - Mongo.getDB()
 - Mongo.getReadPrefMode()
 - Mongo.getReadPrefTagSet()
 - Mongo.isCausalConsistency()
 - Mongo.setCausalConsistency()
 - Mongo.setReadPref()
 - Mongo.startSession()
 - Mongo.watch()
 - Session
 - SessionOptions
 - Native Methods
 - cat()
 - cd()
 - copyDbpath()
 - getHostName()
 - getMemInfo()
 - hostname()
 - isInteractive()
 - listFiles()
 - load()
 - ls()
 - md5sumFile()
 - mkdir()
 - pwd()
 - quit()
 - removeFile()
 - resetDbpath()
 - sleep()
 - setVerboseShell()
 - version()
 - _isWindows()
 - _rand()
 - Client-Side Field Level Encryption Methods
 - getKeyVault()
 - KeyVault.createKey()
 - KeyVault.deleteKey()
 - KeyVault.getKey()
 - KeyVault.getKeys()
 - KeyVault.addKeyAlternateName()
 - KeyVault.removeKeyAlternateName()
 - KeyVault.getKeyByAltName()
 - getClientEncryption()
 - ClientEncryption.encrypt()
 - ClientEncryption.decrypt()
 - mongo Shell 方法
 
 - MongoDB Package Components
 - Configuration File Options
 - MongoDB Server Parameters
 - MongoDB Limits and Thresholds
 - Explain Results
 - System Collections
 - 连接字符串URI格式
 - 排序
 - MongoDB的Wire协议
 - 日志消息
 - Exit Codes and Statuses
 - 词汇表
 - 默认的MongoDB端口
 - Default MongoDB Read Concerns/Write Concerns
 - 服务器会话
 - Configuration File Options
 - 默认的MongoDB读/写关注
 - 退出代码和状态
 - MongoDB Limits and Thresholds
 
 -  Operators   
 -  更新说明   
- Release Notes for MongoDB 4.4
 - Release Notes for MongoDB 4.2
 - Release Notes for MongoDB 4.0
 - Release Notes for MongoDB 3.6
 - Release Notes for MongoDB 3.4
 - Release Notes for MongoDB 3.2
 - Release Notes for MongoDB 3.0
 - Release Notes for MongoDB 2.6
 - Release Notes for MongoDB 2.4
 - Release Notes for MongoDB 2.2
 - Release Notes for MongoDB 2.0
 - Release Notes for MongoDB 1.8
 - Release Notes for MongoDB 1.6
 - Release Notes for MongoDB 1.4
 - Release Notes for MongoDB 1.2.x
 - MongoDB Versioning
 
 - 技术支持
 - 开始使用MongoDB开发
 - 联系我们
 - 更多资料
 - 本书使用 GitBook 发布
 
聚合管道阶段
在db.collection.aggregate和db.aggregate方法中 ,管道阶段出现在列表中。文档按顺序通过各个阶段。
阶段
db.collection.aggregate()阶段
除了$out、$merge和$geoNear阶段之外,所有阶段都可以在管道中出现多次。
注意
有关特定运算符的详细信息,包括语法和示例,请单击特定运算符以转到其参考页。
db.collection.aggregate( [ { <stage> }, ... ] )
| 阶段 | 描述 | 
|---|---|
| $addFields | 向文档添加新字段。与$project类似,$addFields重塑了流中的每个文档;具体而言,通过向输出文档添加新字段,该文档包含输入文档和新添加字段中的现有字段。
$set是的别名$addFields。 |  
| $bucket | 根据指定的表达式和存储段边界将传入文档分类为称为存储段的组。 | 
| $bucketAuto | 根据指定的表达式将传入的文档分类为特定数量的组(称为存储桶)。自动确定存储桶边界,以尝试将文档均匀地分配到指定数量的存储桶中。 | 
| $collStats | 返回有关集合或视图的统计信息。 | 
| $count | 返回聚合管道此阶段的文档数量计数。 | 
| $facet | 在同一阶段的同一组输入文档上处理多个聚合管道。支持在一个阶段中创建能够表征多维或多面数据的多面聚合。 | 
| $geoNear | 基于与地理空间点的接近度返回有序的文档流。将$match,$sort和$limit的功能合并到地理空间数据中。输出文档包括附加距离字段,并且可以包括位置标识符字段。 |  
| $graphLookup | 对集合执行递归搜索。对于每个输出文档,添加一个新的 array 字段,该字段包含该文档的递归搜索的遍历结果。 | 
| $group | 按指定的标识符表达式对文档进行分组,并将累加器表达式(如果指定)应用于每个 group。消耗所有输入文档,并为每个不同的 group 输出一个文档。输出文档仅包含标识符字段,如果指定,则包含累积字段。 | 
| $indexStats | 返回有关集合的每个索引的使用的统计信息。 | 
| $limit | 将未修改的前 n 个文档传递给管道,其中 n 是指定的限制。对于每个输入文档,输出一个文档(对于前 n 个文档)或零文档(在前 n 个文档之后)。 | 
| $listSessions | 列出所有活动时间已足够长以传播到system.sessions集合的会话。 |  
| $lookup | 对同一数据库中的另一个集合执行左外连接,以从“已连接”集合中过滤文档以进行处理。 | 
| $match | 过滤文档流以仅允许匹配的文档未经修改地传递到下一个管道阶段。 $match使用标准的 MongoDB 查询。对于每个输入文档,输出一个文档(匹配)或零文档(不匹配)。 |  
| $merge | 将聚合管道的结果文档写入集合。该阶段可以将结果合并(插入新文档,合并文档,替换文档,保留现有文档,使操作失败,使用自定义更新管道处理文档)将结果合并到输出集合中。要使用该$merge阶段,它必须是管道中的最后一个阶段。
4.2版中的新功能。 |  
| $out | 将聚合管道的结果文档写入集合。要使用$out阶段,它必须是管道中的最后一个阶段。 | 
| $planCacheStats | 返回集合的计划缓存信息。 | 
| $project | 重塑流中的每个文档,例如通过添加新字段或删除现有字段。对于每个输入文档,输出一个文档。
另请参阅$unset删除现有字段。 |  
| $redact | 通过基于文档本身中存储的信息限制每个文档的内容来重塑流中的每个文档。包含$project和$match的功能。可用于实现字段级编辑。对于每个输入文档,输出一个或零个文档。 |  
| $replaceRoot | 用指定的嵌入文档替换文档。该操作将替换输入文档中的所有现有字段,包括_id字段。指定嵌入在输入文档中的文档,以将嵌入的文档提升到顶部级别。
$replaceWith是$replaceRoot阶段的别名 。 |  
| $replaceWith | 用指定的嵌入文档替换文档。该操作将替换输入文档中的所有现有字段,包括_id字段。指定嵌入在输入文档中的文档,以将嵌入的文档提升到顶部级别。
$replaceWith是$replaceRoot阶段的别名 。 |  
| $sample | 从输入中随机选择指定数量的文档。 | 
| $set | 将新字段添加到文档。与$project相似,$set重塑流中的每个文档;具体而言,通过向输出文档添加新字段,该输出文档既包含输入文档中的现有字段,又包含新添加的字段。
$set是$addFields阶段的别名。 |  
| $skip | 跳过前 n 个文档,其中 n 是指定的跳过编号,并将未修改的其余文档传递给管道。对于每个输入文档,输出零文档(对于前 n 个文档)或一个文档(如果在前 n 个文档之后)。 | 
| $sort | 按指定的排序 key 重新排序文档流。只有顺序改变;文档保持不变。对于每个输入文档,输出一个文档。 | 
| sortByCount | 根据指定表达式的 value 对传入文档进行分组,然后计算每个不同 group 中的文档计数。 | 
| $unset | 从文档中删除/排除字段。
$unset是$project删除字段的阶段的别名。 |  
| $unwind | 从输入文档解构 array 字段以输出每个元素的文档。每个输出文档都使用元素 value 替换 array。对于每个输入文档,输出 n 个文档,其中 n 是 array 元素的数量,对于空 array 可以为零。 | 
对于要在管道阶段使用的聚合表达式运算符,请参阅聚合管道操作符。
db.aggregate()阶段
从 version 3.6 开始,MongoDB 还提供了db.aggregate方法:
db.aggregate( [ { <stage> }, ... ] )
以下阶段使用db.aggregate()方法而不是db.collection.aggregate()方法。
| 阶段 | 描述 | 
|---|---|
| $currentOp | 返回有关 MongoDB 部署的活动 and/or 休眠操作的信息。 | 
| $listLocalSessions | 列出最近在当前连接的mongos或mongod实例上使用的所有 active 会话。这些会话可能尚未传播到system.sessions集合。 |  
阶段可用于更新
从MongoDB 4.2开始,您可以使用聚合管道在以下位置进行更新:
对于更新,管道可以包括以下阶段:
$addFields及其别名$set$project及其别名$unset$replaceRoot及其别名$replaceWith。
按字母顺序排列的阶段列表
| 阶段 | 描述 | 
|---|---|
| $addFields | 向文档添加新字段。输出包含输入文档和新添加字段中所有现有字段的文档。 | 
| $bucket | 根据指定的表达式和存储段边界将传入文档分类为称为存储段的组。 | 
| $bucketAuto | 根据指定的表达式将传入的文档分类为特定数量的组(称为存储桶)。自动确定存储桶边界,以尝试将文档均匀地分配到指定数量的存储区中。 | 
| $collStats | 返回有关集合或视图的统计信息。 | 
| $count | 返回聚合管道此阶段的文档数量计数。 | 
| $currentOp | 返回有关 MongoDB 部署的活动 and/or 休眠操作的信息。要运行,请使用db.aggregate()方法。 |  
| $facet | 在同一组输入文档的单个阶段内处理多个聚合管道。允许创建能够在单个阶段中跨多个维度或方面表征数据的 多面聚合。 | 
| $geoNear | 基于与地理空间点的接近度返回有序的文档流。将$match,$sort和$limit的功能合并到地理空间数据中。输出文档包括附加距离字段,并且可以包括位置标识符字段。 |  
| $graphLookup | 对集合执行递归搜索。对于每个输出文档,添加一个新的 array 字段,该字段包含该文档的递归搜索的遍历结果。 | 
| $group | 按指定的标识符表达式对文档进行分组,并将累加器表达式(如果指定)应用于每个 group。消耗所有输入文档,并为每个不同的 group 输出一个文档。输出文档仅包含标识符字段,如果指定,则包含累积字段。 | 
| $indexStats | 返回有关集合的每个索引的使用的统计信息。 | 
| $limit | 将未修改的前 n 个文档传递给管道,其中 n 是指定的限制。对于每个输入文档,输出一个文档(对于前 n 个文档)或零文档(在前 n 个文档之后)。 | 
| $listLocalSessions | 列出最近在当前连接的mongos或mongod实例上使用的所有 active 会话。这些会话可能尚未传播到system.sessions集合。 |  
| $listSessions | 列出所有活动时间已足够长以传播到system.sessions集合的会话。 |  
| $lookup | 对同一数据库中的另一个集合执行左外连接,以从“已连接”集合中过滤文档以进行处理。 | 
| $match | 过滤文档流以仅允许匹配的文档未经修改地传递到下一个管道阶段。 $match使用标准的 MongoDB 查询。对于每个输入文档,输出一个文档(匹配)或零文档(不匹配)。 |  
| $merge | 将聚合管道的结果文档写入集合。该阶段可以将结果合并(插入新文档,合并文档,替换文档,保留现有文档,使操作失败,使用自定义更新管道处理文档)将结果合并到输出集合中。要使用该$merge阶段,它必须是管道中的最后一个阶段。
4.2版中的新功能。 |  
| $out | 将聚合管道的结果文档写入集合。要使用$out阶段,它必须是管道中的最后一个阶段。 |  
| $planCacheStats | 返回集合的计划缓存信息。 | 
| $project | 重新整形流中的每个文档,例如添加新字段或删除现有字段。对于每个输入文档,输出一个文档。 | 
| $redact | 通过基于文档本身中存储的信息限制每个文档的内容来重塑流中的每个文档。包含$project和$match的功能。可用于实现字段级编辑。对于每个输入文档,输出一个或零个文档。 |  
| $replaceRoot | 用指定的嵌入文档替换文档。该操作将替换输入文档中的所有现有字段,包括_id字段。指定嵌入在输入文档中的文档,以将嵌入的文档提升到顶部级别。 |  
| $replaceWith | 用指定的嵌入文档替换文档。该操作将替换输入文档中的所有现有字段,包括_id字段。指定嵌入在输入文档中的文档,以将嵌入的文档提升到顶部级别。
别名$replaceRoot。 |  
| $sample | 从输入中随机选择指定数量的文档。 | 
| $set | 将新字段添加到文档。输出包含输入文档中所有现有字段和新添加的字段的文档。
别名$addFields。 |  
| $skip | 跳过前 n 个文档,其中 n 是指定的跳过编号,并将未修改的其余文档传递给管道。对于每个输入文档,输出零文档(对于前 n 个文档)或一个文档(如果在前 n 个文档之后)。 | 
| $sort | 按指定的排序 key 重新排序文档流。只有顺序改变;文件保持不变。对于每个输入文档,输出一个文档。 | 
| $sortByCount | 根据指定表达式的值对传入文档进行分组,然后计算每个不同组中的文档数。 | 
| $unwind | 从输入文档解构 array 字段以输出每个元素的文档。每个输出文档都使用元素 value 替换 array。对于每个输入文档,输出 n 个文档,其中 n 是 array 元素的数量,对于空 array 可以为零。 | 
译者:李冠飞
校对:
Copyright © 上海锦木信息技术有限公司 all right reserved,powered by Gitbook文件修订时间: 2020-12-18 11:34:57
