Skip to content

Instantly share code, notes, and snippets.

View prakashthegyan's full-sized avatar

Gyan Prakash Tripathi prakashthegyan

View GitHub Profile
import pymongo
import pprint
mongo_uri = "mongodb://localhost:27017/"
client = pymongo.MongoClient(mongo_uri)
table.find().sort("_id",pymongo.DESCENDING)
df.to_csv('StructuredData.csv',index=False)
import pandas as pd
samples=table.find().sort("_id",pymongo.DESCENDING)[:100]
df=pd.DataFrame(samples)
df.head()
testInsert=mycoll.insert_one({"country":'India'}).inserted_id
client.list_database_names()
mydb=client.testDB
mycoll=mydb.testColl
myquery = ({ "name":{"$in": ["Gyan","Eliot"]}})
x = table.delete_many(myquery)
print(x.deleted_count, " documents deleted.")
table.delete_one({'name':'Mike'})
table.find_one({'name':'Mike'})
from bson.objectid import ObjectId
post_id=final.inserted_ids[0]
def parser(post_id):
document = table.find_one({'_id': ObjectId(post_id)})
return document
parser(post_id)