MongoDB vs RDBMS
client = MongoClient() |
example: - client = MongoClient(‘localhost’, 27017 ) |
client = MongoClient(“mongodb: / / localhost: 27017 / ”) |
from pymongo import MongoClient # creation of MongoClient client = MongoClient(“mongodb: / / localhost: 27017 / ”) # Access database mycollection = mydatabase[‘myTable’] # dictionary to be added in the database title: 'MongoDB and Python' , tags: [ 'mongodb' , 'database' , 'NoSQL' ], } # inserting the data in the database |
for i in mydatabase.myTable.find({title: 'MongoDB and Python' }) |
print (mydatabase.myTable.count({title: 'MongoDB and Python' })) |
print (mydatabase.myTable.find({title: 'MongoDB and Python' }).count()) |
conn = MongoClient() except : db = conn.mydatabase # Created or Switched to collection names: myTable # To find() all the entries inside collection name 'myTable' for record in cursor: |
$regex
to do contains searches.cursor = source.find({'title': {'$regex':search_term}}).limit(25)
$text
& $search
. You first need to set a text index, then use it:$regex
, as answered here: https://stackoverflow.com/a/10616781/641627