Python code:
1 ImportPymongo2 3 #get local port, activate MONGO client4Client = Pymongo. Mongoclient ('localhost', 27017)5 6 #Create a database7MyData = client['MyData']8 9 #Create a formTenSheet_tab_one = mydata['Sheet_tab_one'] One A #process a local TXT document, and then read all the text, and then the text is structured, and the number of words stored in each line is saved . - #/users/heyang/desktop/text file containing text content. txt - the #path = '/users/heyang/desktop/Changjiang Power analysis report . - #with open (path, ' R ') as F: - #lines = F.readlines () - #For Index,line in Enumerate (lines): + #If Len (Line.split ()) >0: - #data = { + #' index ': index, A #"line": Line, at #' words ': Len (Line.split ()) - # } - #print (data) - #sheet_tab_one.insert_one (data) - - #Table Insert Data method Insert_one, will not clear the original data, repeated add in in - #displaying data in a database to #$lt $lte $gt $gte $ne, + #in turn, equivalent to < <= > >=! = - #L means less,g means greater e means equal n means not the forIteminchSheet_tab_one.find ({'Index':{'$lt': 5}}): * Print(item)
Here are the operators for the database, which you need to be familiar with and write down to use:
Getting started with Python's database MongoDB