On this page本页内容
db.collection.aggregate()
Change2dsphere
Index Version 2The following 2.6 changes can affect the compatibility with older versions of MongoDB. See Release Notes for MongoDB 2.6 for the full list of the 2.6 changes.
MongoDB 2.6 implements a stronger enforcement of the limit on index key
.
Creating indexes will error if an index key in an existing document exceeds the limit:
db.collection.ensureIndex()
, db.collection.reIndex()
, compact
, and repairDatabase
will error and not create the index. Previous versions of MongoDB would create the index but not index such documents.db.collection.reIndex()
, compact
, and repairDatabase
drop all the indexes from a collection and then recreate them sequentially, the error from the index key limit prevents these operations from rebuilding any remaining indexes for the collection and, in the case of the repairDatabase
command, from continuing with the remainder of the process.Inserts will error:
db.collection.insert()
and other operations that perform inserts (e.g. db.collection.save()
and db.collection.update()
with upsert
that result in inserts) will fail to insert if the new document has an indexed field whose corresponding index entry exceeds the limit. Previous versions of MongoDB would insert but not index such documents.mongorestore
and mongoimport
will fail to insert if the new document has an indexed field whose corresponding index entry exceeds the limit.Updates will error:
db.collection.update()
and db.collection.save()
operations on an indexed field will error if the updated value causes the index entry to exceed the limit.Chunk Migration will fail:
Secondary members of replica sets will warn:
mongo
shell to your MongoDB 2.4 database and run the method.If you have an existing data set and want to disable the default index key length validation so that you can upgrade before resolving these indexing issues, use the failIndexKeyTooLong
parameter.
In MongoDB 2.6, create and re-index operations fail when the index key refers to an empty field, e.g. "a..b" : 1
or the field name starts with a dollar sign ($
).
db.collection.ensureIndex()
will not create a new index with an invalid or empty key name.db.collection.reIndex()
, compact
, and repairDatabase
will error if an index exists with an invalid or empty key name.Previous versions of MongoDB allow the index.
mongo
shell to your MongoDB 2.4 database and run the method.ensureIndex
and Existing Indexes¶db.collection.ensureIndex()
now errors:
db.collection.ensureIndex()
will error.
db.collection.ensureIndex()
will error.
Previous versions did not create the index but did not error.
mongo
shell write methods db.collection.insert()
, db.collection.update()
, db.collection.save()
and db.collection.remove()
now integrate the write concern directly into the method rather than with a separate getLastError
command to provide acknowledgement of writes whether run interactively in the mongo
shell or non-interactively in a script. In previous versions, these methods exhibited a “fire-and-forget” behavior. [1]mongo
shell that used these methods will now wait for acknowledgement, which take longer than the previous “fire-and-forget” behavior.WriteResult
object that contains the results of the operation, including any write errors and write concern errors, and obviates the need to call getLastError
command to get the status of the results. See db.collection.insert()
, db.collection.update()
, db.collection.save()
and db.collection.remove()
for details.mongos
no longer supports “fire-and-forget” behavior. This limits throughput when writing data to sharded clusters.[1] | In previous versions, when using the mongo shell interactively, the mongo shell automatically called the getLastError command after a write method to provide acknowledgement of the write. Scripts, however, would observe “fire-and-forget”
behavior in previous versions unless the scripts included an explicit call to the getLastError command after a write method. |
Scripts that used these mongo
shell methods for bulk write operations with “fire-and-forget” behavior should use the Bulk()
methods.
In sharded environments, applications using any driver or mongo
shell should use Bulk()
methods for optimal performance when inserting or modifying groups of documents.
For example, instead of:
In MongoDB 2.6, replace with Bulk()
operation:
Bulk method returns a BulkWriteResult
object that contains the result of the operation.
db.collection.aggregate()
Change¶The db.collection.aggregate()
method in the mongo
shell defaults to returning a cursor to the results set. This change enables the aggregation pipeline to return result sets of any size and requires cursor iteration to access the result set. For example:例如:
Previous versions returned a single document with a field results
that contained an array of the result set, subject to the BSON Document size limit. Accessing the result set in the previous versions of MongoDB required accessing the results
field and iterating the array. For example:例如:
db.collection.aggregate()
to return a document with a results
array to handle cursors instead.See also参阅
j: true
to a mongod
or mongos
instance running with --nojournal
option now errors. Previous versions would ignore the j: true
.j: true
specification from the write concern when issued against a mongod
or mongos
instance with --nojournal
or run mongod
or mongos
with journaling.MongoDB 2.6 authorization model changes how MongoDB stores and manages user privilege information:
Ensure that at least one user exists in the admin database. If no user exists in the admin database, add a user. Then upgrade to MongoDB 2.6. Finally, upgrade the user privilege model. See Upgrade MongoDB to 2.6.
Important
Before upgrading the authorization model, you should first upgrade MongoDB binaries to 2.6. For sharded clusters, ensure that all
cluster components are 2.6. If there are users in any database, be sure you have at least one user in the admin
database with the role userAdminAnyDatabase
before upgrading the MongoDB binaries.
See also参阅
CN
)
and the Subject Alternative Name (SAN
) fields to ensure that either the CN
or one of the SAN
entries matches the hostname of the server. As a result, if you currently use SSL and neither
the CN
nor any of the SAN
entries of your current SSL certificates match the hostnames, upgrading to version 2.6 will cause the SSL connections to fail.To allow for the continued use of these certificates, MongoDB provides the allowInvalidCertificates
setting. The setting is available for:
mongod
and mongos
to bypass the validation of SSL certificates on other servers in the cluster.mongo
shell, MongoDB tools that support SSL, and the C++ driver to bypass the validation of server certificates.When using the allowInvalidCertificates
setting, MongoDB logs as a warning the use of the invalid certificates.
Warning
The allowInvalidCertificates
setting bypasses the other certificate validation, such as checks for expiration and valid signatures.
2dsphere
Index Version 2¶MongoDB 2.6 introduces a version 2 of the 2dsphere index. If a document lacks a 2dsphere
index field (or the field is null
or an empty array), MongoDB does not add an entry for the document to the 2dsphere
index. For inserts, MongoDB inserts the document but does not add to the 2dsphere
index.
Previous version would not insert documents where the 2dsphere
index field is a null
or an empty array. For documents that lack the 2dsphere
index field, previous versions would insert and index the document.
2dsphere
index with {
"2dsphereIndexVersion" : 1 }
to create a version 1 index. However, version 1 index cannot use the new GeoJSON geometries.See also参阅
ctime
format.--timeStampFormat
which supports timestamp format in ctime
, iso8601-utc
, and iso8601-local
(new default).bindIp
for RPM/DEB Packages¶bindIp
value attaches MongoDB components to the localhost interface only. These packages set this default in the default configuration file (i.e. /etc/mongod.conf
.)/etc/mongod.conf
file, you will need to set bindIp
before or during the upgrade.There is no default bindIp
setting in any other official MongoDB packages.
globalopcounts
to globalOpcounts
.globalopcounts
to globalOpcounts
.db.collection.remove()
requires a query document as a parameter. In previous versions, the method invocation without a query document deleted all documents in a collection.db.collection.remove()
invocations without a query document, modify the invocations to include an empty document db.collection.remove({})
.""
)..
) or a field name that starts with a dollar sign ($
).""
, replace the whole document. See db.collection.update()
and db.collection.save()
for details on replacing an existing document..
), either replace the whole document or unset
the field. To find fields whose names contain a dot, run db.upgradeCheckAllDBs().$
), unset
or rename
those fields. To find fields whose names start with a dollar sign, run db.upgradeCheckAllDBs().See New Write Operation Protocol for the changes to the write operation protocol, and Insert and Update Improvements for the changes to the insert and update operations. Also consider the documentation of the Restrictions on Field Names
.
$
).Unset
or rename
existing fields whose names start with a dollar sign ($
). Run db.upgradeCheckAllDBs() to find fields whose names start with a dollar sign.If a sparse index results in an incomplete result set for queries and sort operations, MongoDB will not use that index unless a hint()
explicitly specifies the index.
For example, the query { x: { $exists: false } }
will no longer use a sparse index on the x
field, unless explicitly hinted.
hint()
.See Sparse Index On A Collection Cannot Return Complete Results for an example that details the new behavior.
sort()
Specification Values¶The sort()
method only accepts the following values for the sort keys:
1
to specify ascending order for a field,-1
to specify descending order for a field, or$meta
expression to specify sort by the text search score.Any other value will result in an error.
Previous versions also accepted either true
or false
for ascending.
true
or false
to 1
.skip()
and _id
Queries¶explain()
Retains Query Plan Cache¶explain()
no longer clears the query plans cached for that query shape.
In previous versions, explain()
would have the side effect of clearing the query plan cache for that query shape.
See also参阅
The PlanCache()
reference.
$maxDistance
Changes¶$near
queries on GeoJSON data, if the queries specify a $maxDistance
, $maxDistance
must be inside of the $near
document.
In previous version, $maxDistance
could be either inside or outside the $near
document.
$maxDistance
must be a positive value.$near
queries on GeoJSON data that currently have the $maxDistance
outside the $near
document$maxDistance
is a negative value.$uniqueDocs
¶$uniqueDocs
, and geospatial queries no longer return duplicated results when a document matches the query multiple times.$not
Query Behavior Changes¶$not
expressions on an indexed field now match:
For example, if a collection orders
contains the following documents:
If the collection has an index on the price
field:
The following query uses the index to search for documents where price
is not greater than or equal to 50
:
In 2.6, the query returns the following documents:
In previous versions, indexed plans would only return matching documents where the type of the field matches the type of the query predicate:
If using a collection scan, previous versions would return the same results as those in 2.6.
$not
expressions.null
Comparison Queries¶$lt
and $gt
comparisons to null
no longer match documents that are missing the field.null
equality conditions on array elements (e.g. "a.b":
null
) no longer match document missing the nested field a.b
(e.g. a: [ 2, 3 ]
).null
equality queries (i.e. field: null
) now match fields with values undefined
.$all
Operator Behavior Change¶$all
operator is now equivalent to an $and
operation of the specified values. This change in behavior can allow for more matches than previous versions when passed an array of a single nested array (e.g. [ [ "A" ] ]
). When passed an array of a nested array, $all
can now match documents where the field contains the nested array as an element (e.g. field: [ [ "A" ], ... ]
), or the field equals the nested array (e.g. field: [ "A", "B" ]
). Earlier version could only match documents where the field contains the nested array.$all
operator returns no match if the array field contains nested arrays (e.g. field: [ "a", ["b"] ]
) and $all
on the nested field is the element of the nested array (e.g. "field.1": { $all: [ "b" ] }
). Previous versions would return a match.$mod
Operator Enforces Strict Syntax¶The $mod
operator now only accepts an array with exactly two elements, and errors when passed an array with fewer or more elements. See Not Enough Elements Error and Too Many Elements Error for details.
In previous versions, if passed an array with one element, the $mod
operator uses 0
as the second element, and if passed an array with more than two elements, the $mod
ignores all but the first two elements. Previous versions do return an error when passed an empty array.
Ensure that the array passed to $mod
contains exactly two elements:
0
as the second element.$where
Must Be Top-Level¶$where
expressions can now only be at top level and cannot be nested within another expression, such as $elemMatch
.$where
.$exists
and notablescan
¶If the MongoDB server has disabled collection scans, i.e. notablescan
, then $exists
queries that have no indexed solution will error.
MinKey
and MaxKey
Queries¶MinKey
or MaxKey
no longer match documents missing the field.The $elemMatch
query operator no longer traverses recursively into nested arrays.
For example, if a collection test
contains the following document:
In 2.6, the following $elemMatch
query does not match the document:
MongoDB does not support the use of the $text
query operator in mixed sharded cluster deployments that contain both version 2.4 and version 2.6 shards. See Upgrade MongoDB to 2.6 for upgrade instructions.
For sharded clusters, MongoDB 2.6 disallows a shard from refreshing the metadata if the shard name has not been explicitly set.
For mixed sharded cluster deployments that contain both version 2.4 and version 2.6 shards, this change can cause errors when migrating chunks from version 2.4 shards to version 2.6 shards if the shard name is unknown to the version 2.6 shards. MongoDB does not support migrations in mixed sharded cluster deployments.
local.system.replset.members[n].votes
should only have a value of 1 for voting members and 0 for non-voting members. MongoDB treats values other than 1 or 0 as a value of 1 and produces a warning message.local.system.replset.members[n].votes
with values other than 1 or 0 to 1 or 0 as appropriate.MongoDB now uses iso8601-local
when formatting time data in many outputs. This format follows the template YYYY-MM-DDTHH:mm:ss.mmm<+/-Offset>
. For example, 2014-03-04T20:13:38.944-0500
.
This change impacts all clients using Extended JSON in Strict mode, such as mongoexport
.