How MongoDB’s Plan Cache works !
When queries will get cached in MongoDB ?
To answer this, not all queries automatically place a query plan in the cache. The query optimizer only caches the plans for those query shapes that can have more than one “viable/feasible plan”.
What this means, for example, is that for each query, it checks to see if there might be more than one index that would satisfy the query.
In our example, imagine we’ve created the following index on below data.
<code>
MongoDB > db.mycol.ensureIndex({“city”:1})
MongoDB > for(var i = 4341; i <= 15341 ; i++){db.mycol.insert({
… _id: i,
… city: “NEW YORK”,
… state: “NY”,
… pop: i+i+i,
… loc: [-74.016323+i-2340, 40.710537+i-2340] });}
WriteResult({ “nInserted” : 1 })
MongoDB >
MongoDB > db.mycol.findOne()
{
“_id” : 4341,
“city” : “NEW YORK”,
“state” : “NY”,
“pop” : 13023,
“loc” : [
1926.9836770000002,
2041.710537
]
}
MongoDB >
MongoDB > db.mycol.find().limit(5)
{ “_id” : 4341, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
{ “_id” : 4344, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13032, “loc” : [ 1929.9836770000002, 2044.710537 ] }
{ “_id” : 4345, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13035, “loc” : [ 1930.9836770000002, 2045.710537 ] }
MongoDB >
MongoDB ></code>
Consider the find with the following form
db.mycol.find({ “city”: “NEW YORK” })
The optimizer has but one option to meaningfully satisfy the request, i.e. to use the “city”:true index.
There is only one viable query plan and it doesn’t get cached.
However, if you add the following indexes {city:1,state:1} & { _id: 1,city: 1} as below.
MongoDB > db.getSiblingDB(“planCacheDb”).runCommand({
… createIndexes: “mycol”,
… indexes: [
… { key: {city: 1},
… name: “city”,
… },
… { key: {city: 1,state: 1},
… name: “city_state”,
… },
… { key: { _id: 1,city: 1},
… name: “id_city”,
… unique: true
… }
… ]})
{
“createdCollectionAutomatically” : true,
“numIndexesBefore” : 1,
“numIndexesAfter” : 4,
“ok” : 1
}
MongoDB >
The same find would result in multiple viable options and the best one would be cached (notice the “rejectedPlans” in the below illustration)
The PlanCache methods are only accessible from a collection’s plan cache object. To retrieve the plan cache object, use the db.collection.getPlanCache() method.
MongoDB > db.mycol.find({ “city”: “NEW YORK” }).explain(“executionStats”)
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“parsedQuery” : {
“city” : {
“$eq” : “NEW YORK”
}
},
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
]
}
}
},
“rejectedPlans” : [
{
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“city” : 1,
“state” : 1
},
“indexName” : “city_state”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
],
“state” : [
“[MinKey, MaxKey]”
]
}
}
}
]
},
“executionStats” : {
“executionSuccess” : true,
“nReturned” : 11001,
“executionTimeMillis” : 12,
“totalKeysExamined” : 11001,
“totalDocsExamined” : 11001,
“executionStages” : {
“stage” : “FETCH”,
“nReturned” : 11001,
“executionTimeMillisEstimate” : 20,
“works” : 11002,
“advanced” : 11001,
“needTime” : 0,
“needYield” : 0,
“saveState” : 87,
“restoreState” : 87,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 11001,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 11001,
“executionTimeMillisEstimate” : 20,
“works” : 11002,
“advanced” : 11001,
“needTime” : 0,
“needYield” : 0,
“saveState” : 87,
“restoreState” : 87,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
]
},
“keysExamined” : 11001,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB >
MongoDB > db.mycol.find({ “city”: “NEW YORK” })
{ “_id” : 4341, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
{ “_id” : 4344, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13032, “loc” : [ 1929.9836770000002, 2044.710537 ] }
{ “_id” : 4345, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13035, “loc” : [ 1930.9836770000002, 2045.710537 ] }
{ “_id” : 4346, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13038, “loc” : [ 1931.9836770000002, 2046.710537 ] }
{ “_id” : 4347, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13041, “loc” : [ 1932.9836770000002, 2047.710537 ] }
{ “_id” : 4348, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13044, “loc” : [ 1933.9836770000002, 2048.710537 ] }
{ “_id” : 4349, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13047, “loc” : [ 1934.9836770000002, 2049.710537 ] }
{ “_id” : 4350, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13050, “loc” : [ 1935.9836770000002, 2050.710537 ] }
{ “_id” : 4351, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13053, “loc” : [ 1936.9836770000002, 2051.710537 ] }
{ “_id” : 4352, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13056, “loc” : [ 1937.9836770000002, 2052.710537 ] }
{ “_id” : 4353, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13059, “loc” : [ 1938.9836770000002, 2053.710537 ] }
{ “_id” : 4354, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13062, “loc” : [ 1939.9836770000002, 2054.710537 ] }
{ “_id” : 4355, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13065, “loc” : [ 1940.9836770000002, 2055.710537 ] }
{ “_id” : 4356, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13068, “loc” : [ 1941.9836770000002, 2056.710537 ] }
{ “_id” : 4357, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13071, “loc” : [ 1942.9836770000002, 2057.710537 ] }
{ “_id” : 4358, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13074, “loc” : [ 1943.9836770000002, 2058.710537 ] }
{ “_id” : 4359, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13077, “loc” : [ 1944.9836770000002, 2059.710537 ] }
{ “_id” : 4360, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13080, “loc” : [ 1945.9836770000002, 2060.710537 ] }
Type “it” for more
MongoDB >
MongoDB >
To see the Shapes from the above query.
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
MongoDB > db.mycol.getPlanCache().getPlansByQuery( { “city”: “NEW YORK” } )
[
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { city: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
“nfeedback” : 0,
“scores” : [ ]
},
“filterSet” : false
},
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { city: 1.0, state: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1,
“state” : 1
},
“indexName” : “city_state”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
],
“state” : [
“[MinKey, MaxKey]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
},
“filterSet” : false
}
]
MongoDB >
MongoDB >
For Plan Query Cache Methods available at : https://docs.mongodb.com/manual/reference/method/js-plan-cache/
MongoDB > db.mycol.explain().update( {_id:4341},{$set: {city: “Florida”}})
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“winningPlan” : {
“stage” : “UPDATE”,
“inputStage” : {
“stage” : “IDHACK”
}
},
“rejectedPlans” : [ ]
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB >
{code:js}
MongoDB > db.mycol.update( {_id:4341},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
MongoDB > db.mycol.update( {_id:4342},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB > db.mycol.update( {_id:4343},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB > db.mycol.update( {_id:4344},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB > db.mycol.update( {_id:4345},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB >
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
MongoDB > db.mycol.explain().update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“parsedQuery” : {
“_id” : {
“$in” : [
4341,
4342,
4343,
4344,
4345
]
}
},
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1
},
“indexName” : “_id_”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
]
}
}
},
“rejectedPlans” : [
{
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1,
“city” : 1
},
“indexName” : “id_city”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
],
“city” : [
“[MinKey, MaxKey]”
]
}
}
}
]
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB >
MongoDB >
MongoDB >
MongoDB >
MongoDB > db.mycol.update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 0 })
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“_id” : {
“$in” : [
4341,
4342,
4343,
4344,
4345
]
}
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
MongoDB > db.mycol.explain().update( {_id : { $lte:4345 }},{$set: {city: “Florida”}})
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“parsedQuery” : {
“_id” : {
“$lte” : 4345
}
},
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1
},
“indexName” : “_id_”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[-inf.0, 4345.0]”
]
}
}
},
“rejectedPlans” : [
{
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1,
“city” : 1
},
“indexName” : “id_city”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[-inf.0, 4345.0]”
],
“city” : [
“[MinKey, MaxKey]”
]
}
}
}
]
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB > db.mycol.update( {_id : { $lte:4345 }},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 0 })
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“_id” : {
“$lte” : 4345
}
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“_id” : {
“$in” : [
4341,
4342,
4343,
4344,
4345
]
}
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
MongoDB > db.mycol.getPlanCache().getPlansByQuery({
… “_id” : {
… “$lte” : 4345
… }
… })
[
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { _id: 1 }, pos: 0\n)”
},
“reason” : {
“score” : 1.8336333333333332,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 5,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“_id” : 1
},
“indexName” : “_id_”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[-inf.0, 4345.0]”
]
},
“keysExamined” : 5,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
“nfeedback” : 0,
“scores” : [ ]
},
“filterSet” : false
},
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { _id: 1.0, city: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 1.8336333333333332,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 5,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“_id” : 1,
“city” : 1
},
“indexName” : “id_city”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[-inf.0, 4345.0]”
],
“city” : [
“[MinKey, MaxKey]”
]
},
“keysExamined” : 5,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
},
“filterSet” : false
}
]
MongoDB >
MongoDB >
MongoDB >
MongoDB >
MongoDB >
MongoDB > db.mycol.getPlanCache().getPlansByQuery( {
… “_id” : {
… “$in” : [
… 4341,
… 4342,
… 4343,
… 4344,
… 4345
… ]
… }
… })
[
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { _id: 1 }, pos: 0\n)”
},
“reason” : {
“score” : 1.8336333333333332,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 5,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“_id” : 1
},
“indexName” : “_id_”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
]
},
“keysExamined” : 6,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
“nfeedback” : 0,
“scores” : [ ]
},
“filterSet” : false
},
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { _id: 1.0, city: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 1.8336333333333332,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 5,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 5,
“executionTimeMillisEstimate” : 0,
“works” : 6,
“advanced” : 5,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“_id” : 1,
“city” : 1
},
“indexName” : “id_city”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
],
“city” : [
“[MinKey, MaxKey]”
]
},
“keysExamined” : 6,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
},
“filterSet” : false
}
]
MongoDB >
MongoDB > db.mycol.getPlanCache().clear()
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[ ]
MongoDB >
MongoDB > db.mycol.explain().update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“parsedQuery” : {
“_id” : {
“$in” : [
4341,
4342,
4343,
4344,
4345
]
}
},
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1
},
“indexName” : “_id_”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
]
}
}
},
“rejectedPlans” : [
{
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“_id” : 1,
“city” : 1
},
“indexName” : “id_city”,
“isMultiKey” : false,
“isUnique” : true,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“_id” : [
“[4341.0, 4341.0]”,
“[4342.0, 4342.0]”,
“[4343.0, 4343.0]”,
“[4344.0, 4344.0]”,
“[4345.0, 4345.0]”
],
“city” : [
“[MinKey, MaxKey]”
]
}
}
}
]
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB >
MongoDB >
MongoDB >
MongoDB > db.mycol.update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Alaska”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB >
MongoDB > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“_id” : {
“$in” : [
4341,
4342,
4343,
4344,
4345
]
}
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB >
Commands used listed below :
db.dropDatabase()
use planCacheDb
db.getSiblingDB(“planCacheDb”).runCommand({
createIndexes: “mycol”,
indexes: [
{ key: {city: 1},
name: “city”,
},
{ key: {city: 1,state: 1},
name: “city_state”,
},
{ key: { _id: 1,city: 1},
name: “id_city”,
unique: true
}
]})
for(var i = 4341; i <= 15341 ; i++){db.mycol.insert({
_id: i,
city: “NEW YORK”,
state: “NY”,
pop: i+i+i,
loc: [-74.016323+i-2340, 40.710537+i-2340] });}
db.mycol.find({ “city”: “NEW YORK” }).explain(“executionStats”)
db.mycol.find({ “city”: “NEW YORK” })
db.mycol.getPlanCache().listQueryShapes()
db.mycol.getPlanCache().getPlansByQuery( { “city”: “NEW YORK” } )
db.mycol.explain().update( {_id:4341},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id:4342},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id:4343},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id:4344},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id:4345},{$set: {city: “Florida”}})
db.mycol.update( {_id:4341},{$set: {city: “Florida”}})
db.mycol.update( {_id:4342},{$set: {city: “Florida”}})
db.mycol.update( {_id:4343},{$set: {city: “Florida”}})
db.mycol.update( {_id:4344},{$set: {city: “Florida”}})
db.mycol.update( {_id:4345},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
db.mycol.explain().update( {_id : { $lte:4345 }},{$set: {city: “Florida”}})
db.mycol.update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
db.mycol.update( {_id : { $lte:4345 }},{$set: {city: “Florida”}})
db.mycol.getPlanCache().listQueryShapes()
db.mycol.update( {_id : { $in: [1,2,3,4,5] }},{$set: {city: “Florida”}})
db.mycol.getPlanCache().listQueryShapes()
db.mycol.update( {_id: { $lte:5 }},{$set: {city: “Florida”}})
db.mycol.getPlanCache().listQueryShapes()
Updates will be cached only once provided if don’t change the where condition in MongoDB.
Below queries will be cached only once ( you can change the order of where statement as below)
db.mycol.update( { city:”XYZ”, state : “XY” },{$set: {city: “ABC”, state: “AB”}},{multi:true})
db.mycol.update( { state : “AB” , city:”ABC”},{$set: { state: “DE”, city: “DEF”}},{multi:true})
db.mycol.update( { city:”DEF”, state : “DE” },{$set: { pop: 123455 } )
There’ll be multiple execution plans cached for below queries as their where conditions are different ?
db.mycol.update( {_id : { $in: [4341,4342,4343,4344,4345] }},{$set: {city: “Florida”}})
db.mycol.update( {_id : { $lte:4345 }},{$set: {city: “Florida”}})
db.mycol.update({ city:{$gt:”XYZ”}, state : “XY” },{$set: {city: “ABC”, state: “AB”}},{multi:true})
db.mycol.update( { city:”XYZ”, state : “XY” },{$set: {city: “ABC”, state: “XY”}},{multi:true})
db.mycol.update( { city:”XYZ”},{$set: {city: “ABC”, state: “XY”}},{multi:true})
db.mycol.update( { state:”XYZ”},{$set: {city: “ABC”, state: “XY”}},{multi:true})
Updates work this way ……………
MongoDB Enterprise > db.dropDatabase()
40, 40.710537+i-2340] });}{ “dropped” : “planCacheDb”, “ok” : 1 }
MongoDB Enterprise > use planCacheDb
switched to db planCacheDb
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.getSiblingDB(“planCacheDb”).runCommand({
… createIndexes: “mycol”,
… indexes: [
… { key: {city: 1},
… name: “city”,
… },
… { key: {city: 1,state: 1},
… name: “city_state”,
… },
… { key: { _id: 1,city: 1},
… name: “id_city”,
… unique: true
… }
… ]})
{
“createdCollectionAutomatically” : true,
“numIndexesBefore” : 1,
“numIndexesAfter” : 4,
“ok” : 1
}
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > for(var i = 4341; i <= 15341 ; i++){db.mycol.insert({
… _id: i,
… city: “NEW YORK”,
… state: “NY”,
… pop: i+i+i,
… loc: [-74.016323+i-2340, 40.710537+i-2340] });}
WriteResult({ “nInserted” : 1 })
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[ ]
MongoDB Enterprise > db.mycol.explain().update( {city:”NEW YORK”},{$set: {city: “Florida”}})
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “planCacheDb.mycol”,
“indexFilterSet” : false,
“parsedQuery” : {
“city” : {
“$eq” : “NEW YORK”
}
},
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
]
}
}
},
“rejectedPlans” : [
{
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“city” : 1,
“state” : 1
},
“indexName” : “city_state”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
],
“state” : [
“[MinKey, MaxKey]”
]
}
}
}
]
},
“serverInfo” : {
“host” : “vm-5cc5-bad6”,
“port” : 27017,
“version” : “3.2.6”,
“gitVersion” : “05552b562c7a0b3143a729aaa0838e558dc49b25”
},
“ok” : 1
}
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[ ]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {city:”NEW YORK”},{$set: {city: “Florida”}})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.find().limit(3)
{ “_id” : 4341, “city” : “Florida”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “NEW YORK”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {city:”NEW YORK”},{$set: {city: “Florida”}},{multi:true})
WriteResult({ “nMatched” : 11000, “nUpserted” : 0, “nModified” : 11000 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.find().limit(3)
{ “_id” : 4341, “city” : “Florida”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “Florida”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “Florida”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {city:”Florida”},{$set: {city: “Alaska”}},{multi:true})
WriteResult({ “nMatched” : 11001, “nUpserted” : 0, “nModified” : 11001 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.find().limit(3)
{ “_id” : 4341, “city” : “Alaska”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “Alaska”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “Alaska”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {_id:4341, city:”Alaska”},{$set: {city: “Tampa”}},{multi:true})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”Alaska”},{$set: {city: “Tampa”}},{multi:true})
WriteResult({ “nMatched” : 11000, “nUpserted” : 0, “nModified” : 11000 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “Alaska”
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().getPlansByQuery( {“state” : “NY”,”city” : “Alaska”})
[
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Node\n—Leaf { city: 1.0, state: 1.0 }, pos: 0\n—Leaf { city: 1.0, state: 1.0 }, pos: 1\n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1,
“state” : 1
},
“indexName” : “city_state”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”Alaska\”, \”Alaska\”]”
],
“state” : [
“[\”NY\”, \”NY\”]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
“nfeedback” : 0,
“scores” : [ ]
},
“filterSet” : false
},
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Node\n—Leaf { city: 1.0 }, pos: 0\n—Leaf \n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“filter” : {
“state” : {
“$eq” : “NY”
}
},
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”Alaska\”, \”Alaska\”]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
},
“filterSet” : false
}
]
MongoDB Enterprise > db.mycol.getPlanCache().getPlansByQuery( {“city” : “Alaska”})
[
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { city: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1
},
“indexName” : “city”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
“nfeedback” : 2,
“scores” : [
{
“score” : NaN
},
{
“score” : NaN
}
]
},
“filterSet” : false
},
{
“details” : {
“solution” : “(index-tagged expression tree: tree=Leaf { city: 1.0, state: 1.0 }, pos: 0\n)”
},
“reason” : {
“score” : 2.0003,
“stats” : {
“stage” : “FETCH”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“docsExamined” : 101,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 101,
“executionTimeMillisEstimate” : 0,
“works” : 101,
“advanced” : 101,
“needTime” : 0,
“needYield” : 0,
“saveState” : 1,
“restoreState” : 1,
“isEOF” : 0,
“invalidates” : 0,
“keyPattern” : {
“city” : 1,
“state” : 1
},
“indexName” : “city_state”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“city” : [
“[\”NEW YORK\”, \”NEW YORK\”]”
],
“state” : [
“[MinKey, MaxKey]”
]
},
“keysExamined” : 101,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
}
},
“feedback” : {
},
“filterSet” : false
}
]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”Tampa”, id: 4341 },{$set: {city: “XYZ”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.find().limit(3)
{ “_id” : 4341, “city” : “Tampa”, “state” : “NY”, “pop” : 13023, “loc” : [ 1926.9836770000002, 2041.710537 ] }
{ “_id” : 4342, “city” : “Tampa”, “state” : “NY”, “pop” : 13026, “loc” : [ 1927.9836770000002, 2042.710537 ] }
{ “_id” : 4343, “city” : “Tampa”, “state” : “NY”, “pop” : 13029, “loc” : [ 1928.9836770000002, 2043.710537 ] }
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”Tampa”,_id: 4341 },{$set: {city: “XYZ”}},{multi:true})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “Tampa”,
“id” : 4341
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“state” : “NY”,
“city” : “Alaska”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,_id: 4341,pop : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “Tampa”,
“id” : 4341
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“state” : “NY”,
“city” : “Alaska”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,_id: 4341,pop_ : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “Tampa”,
“id” : 4341
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“city” : “NEW YORK”
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“state” : “NY”,
“city” : “Alaska”
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().clear()
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[ ]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,id: 4341,pop : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “XYZ”,
“id” : 4341,
“pop” : 13023
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,_id: 4341,pop : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “XYZ”,
“id” : 4341,
“pop” : 13023
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().clear()
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,_id: 4341,pop : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[ ]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,xyz: 4341,pop : 13023 },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “XYZ”,
“xyz” : 4341,
“pop” : 13023
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.update( {state: “NY”, city:”XYZ”,xyz: 4341,pop : 13023,extra:”yxz” },{$set: {city: “ABC”}},{multi:true})
WriteResult({ “nMatched” : 0, “nUpserted” : 0, “nModified” : 0 })
MongoDB Enterprise >
MongoDB Enterprise > db.mycol.getPlanCache().listQueryShapes()
[
{
“query” : {
“state” : “NY”,
“city” : “XYZ”,
“xyz” : 4341,
“pop” : 13023,
“extra” : “yxz”
},
“sort” : {
},
“projection” : {
}
},
{
“query” : {
“state” : “NY”,
“city” : “XYZ”,
“xyz” : 4341,
“pop” : 13023
},
“sort” : {
},
“projection” : {
}
}
]
MongoDB Enterprise >