View store to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.to_csv('StructuredData.csv',index=False) |
View storing to a dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
samples=table.find().sort("_id",pymongo.DESCENDING)[:100] | |
df=pd.DataFrame(samples) | |
df.head() |
View insert in created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testInsert=mycoll.insert_one({"country":'India'}).inserted_id | |
client.list_database_names() |
View create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mydb=client.testDB | |
mycoll=mydb.testColl |
View delete many
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myquery = ({ "name":{"$in": ["Gyan","Eliot"]}}) | |
x = table.delete_many(myquery) | |
print(x.deleted_count, " documents deleted.") |
View delete mike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table.delete_one({'name':'Mike'}) |
View mike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table.find_one({'name':'Mike'}) |
View find multiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table.find_one({"name":'Gyan'}) |
View multiple insert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder