Skip to content

Instantly share code, notes, and snippets.

View aniruddha27's full-sized avatar

Aniruddha Bhandari aniruddha27

View GitHub Profile
/* Sample data */
insert into emp (EMPID, NAME, JOB, SALARY)
values
(201, 'ANIRUDDHA', 'ANALYST', 2100),
(212, 'LAKSHAY', 'DATA ENGINEER', 2700),
(209, 'SIDDHARTH', 'DATA ENGINEER', 3000),
(232, 'ABHIRAJ', 'DATA SCIENTIST', 2500),
(205, 'RAM', 'ANALYST', 2500),
(222, 'PRANAV', 'MANAGER', 4500),
(202, 'SUNIL', 'MANAGER', 4800),
# Query stats
pprint(db.restaurants.find({'cuisine':'French','grades.score':{'$gt':5}}).explain()['executionStats'])
# Query stats
pprint(db.restaurants.find({'cuisine':'American'}).explain()['executionStats'])
pprint(db.restaurants.find().explain())
# Multiple token search
db.restaurants.find_one({"$text": {"$search": "Chinese -Restaurant"}})
# Multiple token search
db.restaurants.find_one({"$text": {"$search": "Chinese Kitchen"}})
# Find restaurants with Kitchen in their name
db.restaurants.find_one({"$text": {"$search": "Kitchen"}})
# Drop indexes
db.restaurants.drop_indexes()
# Create text index
db.restaurants.create_index([('name', 'text')],
name='restaurant_name')
# List indexes
pprint(db.restaurants.index_information())
# Query stats
pprint(db.restaurants.find({'cuisine':'French'}).explain()['executionStats'])
# Query stats
pprint(db.restaurants.find({'cuisine':'French','grades.score':{'$gt':2}}).explain()['executionStats'])