Alongside MongoDB there are many others NoSQL dbs. An short summary of available db options and theirs features can be found here.
How to install MongoDB
- Create a cloud instance
- Download the software into your cloud http://www.mongodb.org/downloads
- Install and start your mongod server process http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
It is important to note that data bases will be created dynamically after you insert a first data into a collection (e.i insert a row into your table in the db - collection is a name for table in mongo).
http://docs.mongodb.org/manual/reference/sql-comparison/
http://docs.mongodb.org/manual/tutorial/getting-started/
http://www.mkyong.com/mongodb/how-to-create-database-or-collection-in-mongodb/
How to insert data into table
http://docs.mongodb.org/manual/tutorial/getting-started/
# start the shell interpreter $ mongo > show dbs help (empty) local 0.078125GB test (empty) > use rado switched to db rado > j = { name : "hello word" } { "name" : "hello word" } > k = { x : 3 } { "x" : 3 } > db.mycollection1.insert(j) > db.mycollection1.insert(k) > show dbs help (empty) local 0.078125GB rado 0.203125GB <<< test (empty) > use rado > show collections mycollection1 <<<<< system.indexes > db.mycollection1.find() { "_id" : ObjectId("52767264795748b715336b87"), "x" : 3 } { "_id" : ObjectId("5276726a795748b715336b88"), "name" : "hello word" }
Mongo shell commands
http://docs.mongodb.org/manual/reference/method/
Install python API library for MongoDB
- Install the library
http://docs.mongodb.org/ecosystem/drivers/python/
apt-get install python-pymongo
- Customize the bash environment and install ipython
apt-get install ipython
Your first Python script that connects to MongoDB
http://api.mongodb.org/python/current/tutorial.html
http://docs.mongodb.org/manual/reference/method/db.collection.insert/
Example Python code to insert data to our Mongo collection:
# rado-hello-world.py import pymongo from pymongo import MongoClien client = MongoClient() db = client['rado'] db.collection_names() [u'system.indexes', u'mycollection1'] collection = db['mycollection1'] for doc in collection.find(): ....: print doc ....: {u'x': 3.0, u'_id': ObjectId('52767264795748b715336b87')} {u'_id': ObjectId('5276726a795748b715336b88'), u'name': u'hello word'} l = { "from" : "python", "mytext" : "hello from python" } collection.insert(l) ObjectId('52767d071d011c22eb1a7de5') for doc in collection.find(): print doc ....: {u'x': 3.0, u'_id': ObjectId('52767264795748b715336b87')} {u'_id': ObjectId('5276726a795748b715336b88'), u'name': u'hello word'} {u'_id': ObjectId('52767d071d011c22eb1a7de5'), u'from': u'python', u'mytext': u'hello from python'}
Further info about write operations
Once of the big differences when working with NoSQL is that they are an implement of CRUD instead of ACID operation.
http://rsmith.co/opinion/technology/2012/11/05/mongodb-gotchas-and-how-to-avoid-them/
http://docs.mongodb.org/manual/core/write-operations/
http://docs.mongodb.org/manual/core/write-concern/
http://api.mongodb.org/python/current/api/pymongo/mongo_client.html#module-pymongo.mongo_client
We could say than that the performance increase is at the cost of security and integrity. If you don't want to lost any data and see errors as you type the commands you can use the options below when connecting to mongo DB. Please keep in mind that this trade off will have some performance implication in busy production systems although
# default >>> client = MongoClient() >>> client2 = MongoClient( j=True, fsync=True ) >>> client2.write_concern {'fsync': True, 'j': True} >>> client.write_concern {}
No comments:
Post a Comment