Skip to content

Instantly share code, notes, and snippets.

Avatar

Gyan Prakash Tripathi prakashthegyan

View GitHub Profile
View store to file
df.to_csv('StructuredData.csv',index=False)
View storing to a dataframe
import pandas as pd
samples=table.find().sort("_id",pymongo.DESCENDING)[:100]
df=pd.DataFrame(samples)
df.head()
View insert in created
testInsert=mycoll.insert_one({"country":'India'}).inserted_id
client.list_database_names()
View create
mydb=client.testDB
mycoll=mydb.testColl
View delete many
myquery = ({ "name":{"$in": ["Gyan","Eliot"]}})
x = table.delete_many(myquery)
print(x.deleted_count, " documents deleted.")
View delete mike
table.delete_one({'name':'Mike'})
View mike
table.find_one({'name':'Mike'})
View find multiple
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)
View filter 1
table.find_one({"name":'Gyan'})
View multiple insert
import datetime
new_posts = [{"name": "Mike",
"username": "latestpost!",
"date": datetime.datetime(2009, 11, 12, 11, 14)},
{"name": "Eliot",
"title": "onceAgain",
"text": "and pretty easy too!",
"date": datetime.datetime(2009, 11, 10, 10, 45)}]
final = table.insert_many(new_posts)