w3resource

MongoDB: cursor.showDiskLoc() method

cursor.showDiskLoc

The cursor.showDiskLoc() method is used to modify the output of a query by adding a field $diskLoc to matching documents. 

Syntax:

cursor.readPref(mode, tagSet)

Parameters:

Name Description Required /
Optional
Type
mode One of the following read preference modes: primary, primaryPreferred, secondary, secondaryPreferred, or nearest Required string
tagSet A tag set used to specify custom read preference modes. For details. Optional array

NOTE:You must apply readPref() to the cursor before retrieving any documents from the database.

Sample document in the restaurants collection:


{
  "address": {
     "building": "1007",
     "coord": [ -73.856077, 40.848447 ],
     "street": "Morris Park Ave",
     "zipcode": "10462"
  },
  "borough": "Bronx",
  "cuisine": "Bakery",
  "grades": [
     { "date": { "$date": 1393804800000 }, "grade": "A", "score": 2 },
     { "date": { "$date": 1378857600000 }, "grade": "A", "score": 6 },
     { "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 },
     { "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 },
     { "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 }
  ],
  "name": "Morris Park Bake Shop",
  "restaurant_id": "30075445"
}
.....

Example: MongoDB: cursor.readPref() method

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.restaurants.find({"cuisine" : "American "}).showDiskLoc();

Output:

>
> db.restaurants.find({"cuisine" : "American "}).showDiskLoc();
{ "_id" : ObjectId("55c3043ab165fa6355ec5c8c"), "address" : { "building" : "2780", "coord" : [ -73.98241999999999, 40.579505 ], "street" : "Stillwell Avenue", "zipcode" : "11224" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-06-10T00:00:00Z"), "grade" : "A
", "score" : 5 }, { "date" : ISODate("2013-06-05T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-04-13T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2011-10-12T00:00:00Z"), "grade" : "A", "score" : 12 } ], "name" : "Riviera Caterer", "restaurant_id" : "40356018"
, "$diskLoc" : { "file" : 0, "offset" : 165552 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c8e"), "address" : { "building" : "8825", "coord" : [ -73.8803827, 40.7643124 ], "street" : "Astoria Boulevard", "zipcode" : "11369" }, "borough" : "Queens", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-11-15T00:00:00Z"), "grade" : "Z", "sco
re" : 38 }, { "date" : ISODate("2014-05-02T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-03-02T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-02-10T00:00:00Z"), "grade" : "A", "score" : 13 } ], "name" : "Brunos On The Boulevard", "restaurant_id" : "4035615
1", "$diskLoc" : { "file" : 0, "offset" : 166576 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c91"), "address" : { "building" : "6409", "coord" : [ -74.00528899999999, 40.628886 ], "street" : "11 Avenue", "zipcode" : "11219" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-07-18T00:00:00Z"), "grade" : "A", "sco
re" : 12 }, { "date" : ISODate("2013-07-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-02-13T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-08-16T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2011-08-17T00:00:00Z"), "grade" : "A", "scor
e" : 11 } ], "name" : "Regina Caterers", "restaurant_id" : "40356649", "$diskLoc" : { "file" : 0, "offset" : 168624 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c93"), "address" : { "building" : "2300", "coord" : [ -73.8786113, 40.8502883 ], "street" : "Southern Boulevard", "zipcode" : "10460" }, "borough" : "Bronx", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-05-28T00:00:00Z"), "grade" : "A", "sco
re" : 11 }, { "date" : ISODate("2013-06-19T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2012-06-15T00:00:00Z"), "grade" : "A", "score" : 3 } ], "name" : "Wild Asia", "restaurant_id" : "40357217", "$diskLoc" : { "file" : 0, "offset" : 169648 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c94"), "address" : { "building" : "7715", "coord" : [ -73.9973325, 40.61174889999999 ], "street" : "18 Avenue", "zipcode" : "11214" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-04-16T00:00:00Z"), "grade" : "A", "sc
ore" : 5 }, { "date" : ISODate("2013-04-23T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2012-04-24T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2011-12-16T00:00:00Z"), "grade" : "A", "score" : 2 } ], "name" : "C & C Catering Service", "restaurant_id" : "40357437",
 "$diskLoc" : { "file" : 0, "offset" : 170160 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c96"), "address" : { "building" : "1", "coord" : [ -73.96926909999999, 40.7685235 ], "street" : "East   66 Street", "zipcode" : "10065" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-05-07T00:00:00Z"), "grade" : "A"
, "score" : 3 }, { "date" : ISODate("2013-05-03T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2012-04-30T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2011-12-27T00:00:00Z"), "grade" : "A", "score" : 0 } ], "name" : "1 East 66Th Street Kitchen", "restaurant_id" : "4
0359480", "$diskLoc" : { "file" : 0, "offset" : 171184 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c9b"), "address" : { "building" : "522", "coord" : [ -73.95171, 40.767461 ], "street" : "East   74 Street", "zipcode" : "10021" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-09-02T00:00:00Z"), "grade" : "A", "score
" : 12 }, { "date" : ISODate("2013-12-19T00:00:00Z"), "grade" : "B", "score" : 16 }, { "date" : ISODate("2013-05-28T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-12-07T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-03-29T00:00:00Z"), "grade" : "A", "score"
 : 11 } ], "name" : "Glorious Food", "restaurant_id" : "40361521", "$diskLoc" : { "file" : 0, "offset" : 305840 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5c9c"), "address" : { "building" : "284", "coord" : [ -73.9829239, 40.6580753 ], "street" : "Prospect Park West", "zipcode" : "11215" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-11-19T00:00:00Z"), "grade" : "A", "s
core" : 11 }, { "date" : ISODate("2013-11-14T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2012-12-05T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-05-17T00:00:00Z"), "grade" : "A", "score" : 11 } ], "name" : "The Movable Feast", "restaurant_id" : "40361606",
"$diskLoc" : { "file" : 0, "offset" : 306352 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5ca1"), "address" : { "building" : "730", "coord" : [ -73.96805719999999, 40.7925587 ], "street" : "Columbus Avenue", "zipcode" : "10025" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-09-12T00:00:00Z"), "grade" : "B
", "score" : 26 }, { "date" : ISODate("2013-08-28T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-03-25T00:00:00Z"), "grade" : "B", "score" : 20 }, { "date" : ISODate("2012-02-14T00:00:00Z"), "grade" : "A", "score" : 12 } ], "name" : "P & S Deli Grocery", "restaurant_id" : "40362
264", "$diskLoc" : { "file" : 0, "offset" : 309424 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5ca2"), "address" : { "building" : "18", "coord" : [ -73.996984, 40.72589 ], "street" : "West Houston Street", "zipcode" : "10012" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-04-03T00:00:00Z"), "grade" : "A", "sco
re" : 9 }, { "date" : ISODate("2013-04-05T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2012-03-21T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2011-04-27T00:00:00Z"), "grade" : "A", "score" : 5 } ], "name" : "Angelika Film Center", "restaurant_id" : "40362274", "
$diskLoc" : { "file" : 0, "offset" : 309936 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5ca7"), "address" : { "building" : "107", "coord" : [ -74.00920839999999, 40.7132925 ], "street" : "Church Street", "zipcode" : "10007" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-07-18T00:00:00Z"), "grade" : "A",
 "score" : 12 }, { "date" : ISODate("2014-02-26T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-08-26T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-02-01T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-01-17T00:00:00Z"), "grade" : "A", "
score" : 13 }, { "date" : ISODate("2011-10-18T00:00:00Z"), "grade" : "A", "score" : 11 } ], "name" : "Downtown Deli", "restaurant_id" : "40363021", "$diskLoc" : { "file" : 0, "offset" : 313008 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5caa"), "address" : { "building" : "7615", "coord" : [ -74.0228449, 40.6281815 ], "street" : "5 Avenue", "zipcode" : "11209" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-12-04T00:00:00Z"), "grade" : "A", "score" : 1
0 }, { "date" : ISODate("2013-10-24T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-04-18T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2012-04-05T00:00:00Z"), "grade" : "A", "score" : 13 } ], "name" : "Mejlander & Mulgannon", "restaurant_id" : "40363117", "$dis
kLoc" : { "file" : 0, "offset" : 315568 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cad"), "address" : { "building" : "625", "coord" : [ -73.990494, 40.7569545 ], "street" : "8 Avenue", "zipcode" : "10018" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-06-09T00:00:00Z"), "grade" : "A", "score" : 12
 }, { "date" : ISODate("2014-01-10T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-12-07T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2011-12-13T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2011-09-09T00:00:00Z"), "grade" : "A", "score" : 13 }
], "name" : "Cafe Metro", "restaurant_id" : "40363298", "$diskLoc" : { "file" : 0, "offset" : 317104 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cb2"), "address" : { "building" : "87-69", "coord" : [ -73.8309503, 40.7001121 ], "street" : "Lefferts Boulevard", "zipcode" : "11418" }, "borough" : "Queens", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-02-25T00:00:00Z"), "grade" : "A", "s
core" : 7 }, { "date" : ISODate("2013-08-14T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-08-07T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-03-26T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2011-11-04T00:00:00Z"), "grade" : "A", "sco
re" : 0 }, { "date" : ISODate("2011-06-29T00:00:00Z"), "grade" : "A", "score" : 4 } ], "name" : "Snack Time Grill", "restaurant_id" : "40363590", "$diskLoc" : { "file" : 0, "offset" : 321200 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cb5"), "address" : { "building" : "437", "coord" : [ -73.975393, 40.757365 ], "street" : "Madison Avenue", "zipcode" : "10022" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-06-03T00:00:00Z"), "grade" : "A", "score"
 : 9 }, { "date" : ISODate("2013-06-07T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2012-06-29T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-02-06T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2011-06-23T00:00:00Z"), "grade" : "A", "score" :
 13 } ], "name" : "Berkely", "restaurant_id" : "40363685", "$diskLoc" : { "file" : 0, "offset" : 323760 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cb6"), "address" : { "building" : "1031", "coord" : [ -73.9075537, 40.6438684 ], "street" : "East   92 Street", "zipcode" : "11236" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-02-05T00:00:00Z"), "grade" : "A", "sc
ore" : 0 }, { "date" : ISODate("2013-01-29T00:00:00Z"), "grade" : "A", "score" : 3 }, { "date" : ISODate("2011-12-08T00:00:00Z"), "grade" : "A", "score" : 10 } ], "name" : "Sonny'S Heros", "restaurant_id" : "40363744", "$diskLoc" : { "file" : 0, "offset" : 324272 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cba"), "address" : { "building" : "364", "coord" : [ -73.96084119999999, 40.8014307 ], "street" : "West  110 Street", "zipcode" : "10025" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-09-04T00:00:00Z"), "grade" : "
B", "score" : 20 }, { "date" : ISODate("2014-02-26T00:00:00Z"), "grade" : "B", "score" : 23 }, { "date" : ISODate("2013-03-25T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-02-21T00:00:00Z"), "grade" : "A", "score" : 8 } ], "name" : "Spoon Bread Catering", "restaurant_id" : "40
364179", "$diskLoc" : { "file" : 0, "offset" : 326320 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cbc"), "address" : { "building" : "0", "coord" : [ -84.2040813, 9.9986585 ], "street" : "Guardia Airport Parking", "zipcode" : "11371" }, "borough" : "Queens", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-05-16T00:00:00Z"), "grade" : "A", "s
core" : 9 }, { "date" : ISODate("2013-05-10T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2012-05-15T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2011-11-02T00:00:00Z"), "grade" : "C", "score" : 32 } ], "name" : "Terminal Cafe/Yankee Clipper", "restaurant_id" : "4
0364262", "$diskLoc" : { "file" : 0, "offset" : 327344 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cc3"), "address" : { "building" : "1", "coord" : [ -73.97166039999999, 40.764832 ], "street" : "East   60 Street", "zipcode" : "10022" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-10-16T00:00:00Z"), "grade" : "B",
 "score" : 24 }, { "date" : ISODate("2014-05-02T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2013-04-02T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-10-19T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-04-27T00:00:00Z"), "grade" : "B",
"score" : 17 }, { "date" : ISODate("2011-11-29T00:00:00Z"), "grade" : "A", "score" : 11 } ], "name" : "Metropolitan Club", "restaurant_id" : "40364347", "$diskLoc" : { "file" : 0, "offset" : 330928 } }
{ "_id" : ObjectId("55c3043ab165fa6355ec5cc4"), "address" : { "building" : "837", "coord" : [ -73.9712, 40.751703 ], "street" : "2 Avenue", "zipcode" : "10017" }, "borough" : "Manhattan", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-07-22T00:00:00Z"), "grade" : "B", "score" : 19 },
 { "date" : ISODate("2013-09-26T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-02-26T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-04-30T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2011-10-05T00:00:00Z"), "grade" : "A", "score" : 12 } ]
, "name" : "Palm Restaurant", "restaurant_id" : "40364355", "$diskLoc" : { "file" : 0, "offset" : 331952 } }
Type "it" for more

Retrieve the restaurants data from here

Previous: cursor.readPref() method
Next: cursor.size() method



Follow us on Facebook and Twitter for latest update.