儿童艾滋病潜伏期时间:MongoDB For Mac OS

来源:百度文库 编辑:偶看新闻 时间:2024/04/27 18:55:45
MongoDB For Mac OS用MAC OS的包管理工具ports安装(brew也行),类似于linux上的包管理工具,安装方便,升级容易:sudo port install mongodb安装完成后创建data数据目录和log日志目录:sudomkdir/opt/local/data sudomkdir/opt/local/data/db sudomkdir/opt/local/data/log然后启动mongodb数据库:sudo mongod --dbpath /opt/local/data/db --fork --logpath /opt/local/data/log/moongodb.log --logappend使用–fork是使MongoDB以Daemon的方式在后台运行,Daemon方式运行需要指定log文件;如果是普通方式,指定数据库目录就可以。–port参数是指定服务运行的端口,默认是27017。手动安装方式:http://www.mongodb.org/downloads下载安装包后解压即可直接启动所需准备工作就是创建数据存储目录,创建日志文件,这些需要再启动mongodb的时候作为参数示例:
①用tar -zxvf mongodb-linux-x86_64-1.2.4.tgz解压开安装包
②mkdir -p /data/db  创建目录
③cd /data/db 进入db目录下   然后创建mkdir m_data m_log
④进入mongodb解压目录的bin目录下,用
1./mongod -fork --dbpath=./data/db/m_data/ --logpath=./m_log.log  --logappend --port=27017 &启动服务器。命令行访问需要到bin目录执行./mongo命令行用的多的话可以考虑将monogdb安装目录中的bin目录添加到系统$PATH中附加mongodo基本语法以供参考:1、基本操作db.AddUser(username,password) 添加用户db.auth(usrename,password) 设置数据库连接验证db.cloneDataBase(fromhost) 从目标服务器克隆一个数据库db.commandHelp(name) returns the help for the commanddb.copyDatabase(fromdb,todb,fromhost) 复制数据库fromdb—源数据库名称,todb—目标数据库名称,fromhost—源数据库服务器地址db.createCollection(name,{size:3333,capped:333,max:88888}) 创建一个数据集,相当于一个表db.currentOp() 取消当前库的当前操作db.dropDataBase() 删除当前数据库db.eval(func,args) run code server-sidedb.getCollection(cname) 取得一个数据集合,同用法:db['cname'] ordb.getCollenctionNames() 取得所有数据集合的名称列表db.getLastError() 返回最后一个错误的提示消息db.getLastErrorObj() 返回最后一个错误的对象db.getMongo() 取得当前服务器的连接对象get the serverdb.getMondo().setSlaveOk() allow this connection to read from then nonmaster membr of a replica pairdb.getName() 返回当操作数据库的名称db.getPrevError() 返回上一个错误对象db.getProfilingLevel()db.getReplicationInfo() 获得重复的数据db.getSisterDB(name) get the db at the same server as this onewdb.killOp() 停止(杀死)在当前库的当前操作db.printCollectionStats() 返回当前库的数据集状态db.printReplicationInfo()db.printSlaveReplicationInfo()db.printShardingStatus() 返回当前数据库是否为共享数据库db.removeUser(username) 删除用户db.repairDatabase() 修复当前数据库db.resetError()db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into {cmdObj:1}db.setProfilingLevel(level) 0=off,1=slow,2=alldb.shutdownServer() 关闭当前服务程序db.version() 返回当前程序的版本信息2、数据集(表)操作db.test.find({id:10}) 返回test数据集ID=10的数据集db.test.find({id:10}).count() 返回test数据集ID=10的数据总数db.test.find({id:10}).limit(2) 返回test数据集ID=10的数据集从第二条开始的数据集db.test.find({id:10}).skip(8) 返回test数据集ID=10的数据集从0到第八条的数据集db.test.find({id:10}).limit(2).skip(8) 返回test数据集ID=1=的数据集从第二条到第八条的数据db.test.find({id:10}).sort() 返回test数据集ID=10的排序数据集db.test.findOne([query]) 返回符合条件的一条数据db.test.getDB() 返回此数据集所属的数据库名称db.test.getIndexes() 返回些数据集的索引信息db.test.group({key:…,initial:…,reduce:…[,cond:...]})db.test.mapReduce(mayFunction,reduceFunction,)db.test.remove(query) 在数据集中删除一条数据db.test.renameCollection(newName) 重命名些数据集名称db.test.save(obj) 往数据集中插入一条数据db.test.stats() 返回此数据集的状态db.test.storageSize() 返回此数据集的存储大小db.test.totalIndexSize() 返回此数据集的索引文件大小db.test.totalSize() 返回些数据集的总大小db.test.update(query,object[,upsert_bool]) 在此数据集中更新一条数据db.test.validate() 验证此数据集db.test.getShardVersion() 返回数据集共享版本号3、MongoDB语法与现有关系型数据库SQL语法比较MongoDB语法 MySql语法db.test.find({‘name’:'foobar’}) <==> select * from test where name=’foobar’db.test.find() <==> select * from testdb.test.find({‘ID’:10}).count() <==> select count(*) from test where ID=10db.test.find().skip(10).limit(20) <==> select * from test limit 10,20db.test.find({‘ID’:{$in:[25,35,45]}}) <==> select * from test where ID in (25,35,45)db.test.find().sort({‘ID’:-1}) <==> select * from test order by ID descdb.test.distinct(‘name’,{‘ID’:{$lt:20}}) <==> select distinct(name) from test where ID<20db.test.group({key:{‘name’:true},cond:{‘name’:'foo’},reduce:function(obj,prev){prev.msum+=obj.marks;},initial:{msum:0}}) <==> select name,sum(marks) from test group by namedb.test.find(‘this.ID<20′,{name:1}) <==> select name from test where ID<20db.test.insert({‘name’:'foobar’,'age’:25})<==>insert into test (‘name’,'age’) values(‘foobar’,25)db.test.remove({}) <==> delete * from testdb.test.remove({‘age’:20}) <==> delete test where age=20db.test.remove({‘age’:{$lt:20}}) <==> elete test where age<20db.test.remove({‘age’:{$lte:20}}) <==> delete test where age<=20db.test.remove({‘age’:{$gt:20}}) <==> delete test where age>20db.test.remove({‘age’:{$gte:20}}) <==> delete test where age>=20db.test.remove({‘age’:{$ne:20}}) <==> delete test where age!=20db.test.update({‘name’:'foobar’},{$set:{‘age’:36}}) <==> update test set age=36 where name=’foobar’db.test.update({‘name’:'foobar’},{$inc:{‘age’:3}}) <==> update test set age=age+3 wherename=’foobar’参考资料:
http://blog.wangjunfeng.com.cn/?p=78
http://hlee.iteye.com/blog/772882
http://www.douhua.im/2010/04/03/snow-leopard-install-mongodb-with-macports/