文卓软件欢迎大家在更新数据(与关系型差异较大)----------------------------------------------74.6.1增加field---------------------------------------------------------------------84.6.2upset--------------------------------------------------------------------------84.6.3批量更新--------------------------------------------------------------------84.7索引----------------------------------------------------------------------------------85其他------------------------------------------------------------------------------------------95.1使用web获得mongoDB的信息--------------------------------------------------95.2数据备份和恢复-------------------------------------------------------------------95.3导入导出数据----------------------------------------------------------------------96使用MongoDB-----------------------------------------------------------------------------9Email:MSN:wenpengsong@gmail.com-1-文卓软件欢迎大家在下载与安装下载:安装:直接解压即可。2启动使用mongo.exerun启动即可,如下图所示。在LINUX和WINDOWS系统下的使用大同小异,不同的地方主要是默认的数据存储目录。LINUX类系统下存放在/data/db下,而WINDOWS会存放在C:\data\db下。可以在启动时使用--dbpath参数指定存储目录并启动。如:bin\mongod.exe--dbpathd:\data\mongo常用启动参数:run直接启动。例:./mongodrun--dbpath指定特定存储目录启动,若目录不存在则创建。例:./mongod--dbpath/var/data/mongo--port指定端口启动。例:./mongod--port12345控制台的启动使用mongo.exe,如下图所示。Email:MSN:wenpengsong@gmail.com-2-文卓软件欢迎大家在组成,databases由collections组成,collections由documents(相当于行)组成,而documents有fields(相当于列)组成。MongoDB是异步写数据。4常用命令4.1调用命令调用命令的方法db.help();若漏掉()则直接显示方法体。如下图所示。Email:MSN:wenpengsong@gmail.com-3-文卓软件欢迎大家在上讨论相关话题可以看到方法的具体实现。是JavaScript程序。4.2useusedemodb创建demodb,不用担心demodb不会创建,当创建第一个collection时,demodb会自动创建。4.3插入数据db.unicorns.insert({name:'demo',sex:'m',weight:70})插入一个数据,collection为unicorns使用db.getCollectionNames(),会得到unicorns和system.indexes。system.indexes对每个DB都会有,用于记录index。Email:MSN:wenpengsong@gmail.com-4-文卓软件欢迎大家在()会看到document。如下所示usedemodbswitchedtodbdemodbdb.unicorns.insert({name:'demo',sex:'m',weight:70})db.getCollectionNames()[system.indexes,unicorns]db.unicorns.find(){_id:ObjectId(4da6eea3a8d5cd3b72081cf2),name:demo,sex:m,weight:70}db.system.indexes.find(){name:_id_,ns:demodb.unicorns,key:{_id:1},v:0}db.unicorns.insert({name:'Leto',gender:'m',home:'Arrakeen',worm:false})db.unicorns.find(){_id:ObjectId(4da6eea3a8d5cd3b72081cf2),name:demo,sex:m,weight:70}{_id:ObjectId(4da6f09ea8d5cd3b72081cf3),name:Leto,gender:m,home:Arrakeen,worm:false}4.4查询数据先插入测试数据db.unicorns.insert({name:'Horny',dob:newDate(1992,2,13,7,47),loves:['carrot','papaya'],weight:600,gender:'m',vampires:63});db.unicorns.insert({name:'Aurora',dob:newDate(1991,0,24,13,0),loves:['carrot','grape'],weight:450,gender:'f',vampires:43});db.unicorns.insert({name:'Unicrom',dob:newDate(1973,1,9,22,10),loves:['energon','redbull'],weight:984,gender:'m',vampires:182});db.unicorns.insert({name:'Roooooodles',dob:newDate(1979,7,18,18,44),loves:['apple'],weight:575,gender:'m',vampires:99});db.unicorns.insert({name:'Solnara',dob:newDate(1985,6,4,2,1),loves:['apple','carrot','chocolate'],weight:550,gender:'f',vampires:80});db.unicorns.insert({name:'Ayna',dob:newDate(1998,2,7,8,30),loves:['strawberry','lemon'],weight:733,gender:'f',vampires:40});db.unicorns.insert({name:'Kenny',dob:newDate(1997,6,1,10,42),loves:['grape','lemon'],weight:690,gender:'m',vampires:39});db.unicorns.insert({name:'Raleigh',dob:newDate(2005,4,3,0,57),loves:['apple','sugar'],weight:421,gender:'m',vampires:2});db.unicorns.insert({name:'Leia',dob:newDate(2001,9,8,14,53),loves:['apple','watermelon'],weight:601,gender:'f',vampires:33});db.unicorns.insert({name:'Pilot',dob:newDate(1997,2,1,5,3),loves:['apple',Email:MSN:wenpengsong@gmail.com-5-文卓软件欢迎大家在上讨论相关话题'watermelon'],weight:650,gender:'m',vampires:54});db.unicorns.insert({name:'Nimue',dob:newDate(1999