diff --git a/gnowsys-ndf/create_indexes_mongoshell.js b/gnowsys-ndf/create_indexes_mongoshell.js new file mode 100644 index 0000000000..ec051b5d06 --- /dev/null +++ b/gnowsys-ndf/create_indexes_mongoshell.js @@ -0,0 +1,21 @@ +/*run this file from the terminal by typing the command mongo>> class MyDoc(Document): +... structure = { +... 'standard':unicode, +... 'other':{ +... 'deep':unicode, +... }, +... 'notindexed':unicode, +... } +... +... indexes = [ +... { +... 'fields':['standard', 'other.deep'], +... 'unique':True, +... }, +... ] + + In versions before 0.7.1 of mongokit this simple addition would automatically create indexes for the data in mongoDB also. But in later versions this automatic index creation was removed (as people felt that indexes should be created with care directly on the collection). Gstudio uses Mongokit version 0.9.1.1 so this above addition only enables the database class to use the indexes if they are present in the database. We have to now manually create the indexes in mongoDB through mongo shell commands (This is infact told by mongokit as a deprecation warning that indexing is no longer automatic and we have to do it manually). + +2)Index creation: + We can actually use createIndex() command directly in mongoshell individually on various databases for required fields to create indexes. But it will reduce relocation, so we wrote the commands in a js file and then ran the script. + +For Example- + +test.js => + conn=new Mongo() + db=conn.getDB("studio-dev") + db.Nodes.createIndex({'_type':1,'name':1}) + //just keep adding these commands for creating Indexes in desired databases to required fields + +$mongo