Skip to content

Instantly share code, notes, and snippets.

View aniruddha27's full-sized avatar

Aniruddha Bhandari aniruddha27

View GitHub Profile
# Drop index
db.restaurants.drop_indexes()
# Get indexes
db.restaurants.index_information()
# Drop index
db.restaurants.drop_index('cuisine_1')
# Get indexes
db.restaurants.index_information()
# Create new index
db.restaurants.create_index('borough', name="borough_index")
# Get indexes
db.restaurants.index_information()
# Query stats
pprint(db.restaurants.find({'cuisine':'American'}).explain()['executionStats'])
# Create new index
db.restaurants.create_index('cuisine')
# Get indexes
db.restaurants.index_information()
# Find American cuisine restaurants
result = db.restaurants.find({'cuisine':'American'})
for i in result:
print(i)
# Get indexes
db.neighborhoods.index_information()
# Get indexes
db.restaurants.index_information()
# Check document
pprint(db.neighborhoods.find_one())
# Check document
pprint(db.restaurants.find_one())