IMServer:MongoDB: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Created page with "== MongoDB == * 64 bit recommended due to 2gb data size barrier in 32bit * 1.7.4 has some enhancements like 16mb limit per binary record * Binary can be downloaded from * On de...")
 
Line 5: Line 5:
* Binary can be downloaded from  
* Binary can be downloaded from  
* On deployment server, needs a script to be installed in init.d to stop / restart / start mongodb
* On deployment server, needs a script to be installed in init.d to stop / restart / start mongodb
== Creating indexes ==
import pymongo
# connect with the database
try:
conn = pymongo.Connection()
db = conn['clay1']
print 'Connection OK'
except:
print 'Cound not Connect ..'
# loop through all collections
cols = db.collection_names()
for col_name in cols:
# skip if starts with system
if col_name[0:6] <> 'system':
print 'Opening collection : ' + col_name
col = db[col_name]
print '  With %d records'%(col.count())
print '  ' + str(col.index_information())
print '  Creating index ...'
col.ensure_index("name")
print "\r  Done ...    "


== Cookbook ==
== Cookbook ==

Revision as of 16:21, 19 January 2011

MongoDB

  • 64 bit recommended due to 2gb data size barrier in 32bit
  • 1.7.4 has some enhancements like 16mb limit per binary record
  • Binary can be downloaded from
  • On deployment server, needs a script to be installed in init.d to stop / restart / start mongodb


Creating indexes

import pymongo

  1. connect with the database

try: conn = pymongo.Connection() db = conn['clay1'] print 'Connection OK' except: print 'Cound not Connect ..'

  1. loop through all collections

cols = db.collection_names()

for col_name in cols: # skip if starts with system if col_name[0:6] <> 'system': print 'Opening collection : ' + col_name col = db[col_name] print ' With %d records'%(col.count()) print ' ' + str(col.index_information()) print ' Creating index ...' col.ensure_index("name") print "\r Done ... "

Cookbook

How to find if a collection exists

Also it helps if mongo can be queried for existing collections first. That can be done by querying system.namespaces collection in that database, which lists all the collections

<source lang="javascript" show dbs use clay1 db.system.namespaces.find({ "name" :"clay1.n5"}) >

"clay1" is the name of the database, and "n5" is the name of the collection to find