User:Lindenb/Notebook/UMR915/20100914

From OpenWetWare

Jump to: navigation, search

20100913        Top        20100915       


Contents

Mongodb

Downloaded http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.6.2.tgz and the java driver http://cloud.github.com/downloads/mongodb/mongo-java-driver/mongo-2.1.jar on server2

user & group

create a user and group for mongodb

   sudo /usr/sbin/groupadd mongodb
   sudo /usr/sbin/useradd -c "MongoDabatabase User" -M -r -g mongodb mongodb

start

create data dir

  mkdir /GENOTYPAGE/data/mongodb/umr915

start mongo

  sudo -u mongodb /usr/local/package/mongodb-linux-x86_64-1.6.2/bin/mongod --dbpath /GENOTYPAGE/data/mongodb/umr915

insert

insert a project

 > p={_id:"Bru",label:"XXXX",description:"XXXX",creation:"2010-09-14"};
  {

"_id" : "Bru", "label" : "XXXX", "description" : "XXXX", "creation" : "2010-09-14"

   } 
  > use umr915;
  switched to db umr915
  > db.projects.save(p);

find project by id:

  > db.projects.find(); 
  { "_id" : "Bru", "label" : "XXXX", "description" : "XXXX", "creation" : "2010-09-14" }
  > db.projects.find({_id:"doesnotexist"});
  > db.projects.find({_id:"Bru"});
  { "_id" : "Bru", "label" : "XXXX", "description" : "XXXX", "creation" : "2010-09-14" }

insert 10 families:

  for(var i=1;i<= 10;++i) db.families.save({_id:"Br"+i,label:"Br"+i,description:"XXXX Family ID."+i,creation:"2010-09-14",project:"Bru"});
  > db.families.find()                                                                                                                         
  { "_id" : "Br1", "label" : "Br1", "description" : "XXXX Family ID.1", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br2", "label" : "Br2", "description" : "XXXX Family ID.2", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br3", "label" : "Br3", "description" : "XXXX Family ID.3", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br4", "label" : "Br4", "description" : "XXXX Family ID.4", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br5", "label" : "Br5", "description" : "XXXX Family ID.5", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br6", "label" : "Br6", "description" : "XXXX Family ID.6", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br7", "label" : "Br7", "description" : "XXXX Family ID.7", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br8", "label" : "Br8", "description" : "XXXX Family ID.8", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br9", "label" : "Br9", "description" : "XXXX Family ID.9", "creation" : "2010-09-14", "project" : "Bru" }
  { "_id" : "Br10", "label" : "Br10", "description" : "XXXX Family ID.10", "creation" : "2010-09-14", "project" : "Bru" }

create index on families@project:

  db.families.ensureIndex({project:1});

search/explain find

 > db.families.find().explain()
 {
 "cursor" : "BasicCursor",
 "nscanned" : 10,
 "nscannedObjects" : 10,
 "n" : 10,
 "millis" : 0,
 "indexBounds" : {	
   }
 }
  
 > db.families.find({project:"Bru"}).explain()
 {
 "cursor" : "BtreeCursor project_1",
 "nscanned" : 10,
 "nscannedObjects" : 10,
 "n" : 10,
  "millis" : 0,
 "indexBounds" : {
 "project" : [ [ "Bru","Bru"] ]
  }
 }

search with function:

  > db.families.find({$where: function() { return this.label=="Br5";}}) 
  { "_id" : "Br5", "label" : "Br5", "description" : "XXXX Family ID.5", "creation" : "2010-09-14", "project" : "Bru" }

difference between count & size

  > db.families.find().limit(1).count()
  10
  > db.families.find().limit(1).size() 
  1
Personal tools