Navigation
This version of the documentation is archived and no longer supported.

$showDiskLoc

On this page

$showDiskLoc

$showDiskLoc option adds a field $diskLoc to the returned documents. The value of the added $diskLoc field is a document that contains the disk location information:

"$diskLoc": {
  "file": <int>,
  "offset": <int>
}

The mongo shell provides the cursor.showDiskLoc() method for $showDiskLoc:

db.collection.find().showDiskLoc()

You can also specify the $showDiskLoc option in either of the following forms:

db.collection.find( { <query> } )._addSpecial("$showDiskLoc" , true)
db.collection.find( { $query: { <query> }, $showDiskLoc: true } )

Example

The following operation appends the showDiskLoc() method to the db.collection.find() method in order to include in the matching documents the disk location information:

db.collection.find( { a: 1 } ).showDiskLoc()

The operation returns the following documents, which includes the $diskLoc field:

{
  "_id" : ObjectId("53908ccb18facd50a75bfbac"),
  "a" : 1,
  "b" : 1,
  "$diskLoc" : { "file" : 0, "offset" : 16195760 }
}
{
   "_id" : ObjectId("53908cd518facd50a75bfbad"),
   "a" : 1,
   "b" : 2,
   "$diskLoc" : { "file" : 0, "offset" : 16195824 }
}

The projection can also access the added field $diskLoc, as in the following example:

db.collection.find( { a: 1 }, { $diskLoc: 1 } ).showDiskLoc()

The operation returns just the _id field and the $diskLoc field in the matching documents:

{
  "_id" : ObjectId("53908ccb18facd50a75bfbac"),
  "$diskLoc" : { "file" : 0, "offset" : 16195760 }
}
{
   "_id" : ObjectId("53908cd518facd50a75bfbad"),
   "$diskLoc" : { "file" : 0, "offset" : 16195824 }
}
←   $returnKey $snapshot  →