文档详情

mongodb数据库表的操作.docx

发布:2017-07-08约8.93千字共8页下载文档
文本预览下载声明
MongoDB数据表基本操作查看全部数据表?use?ChatRoomswitched?to?db?ChatRoom?show?collectionsAccountChatsystem.indexessystem.users?创建数据表?db.createCollection(Account){ok:1}??db.createCollection(Test,{capped:true, size:10000}) {?ok?:?1?}{ok:1}-- 说明capped:true,表示该集合的结构不能被修改;size:在建表之初就指定一定的空间大小,接下来的插入操作会不断地按顺序APPEND数据在这个预分配好空间的文件中,如果已经超出空间大小,则回到文件头覆盖原来的数据继续插入。这种结构保证了插入和查询的高效性,它不允许删除单个记录,更新的也有限制:不能超过原有记录的大小。这种表效率很高,它适用于一些暂时保存数据的场合,比如网站中登录用户的session信息,又比如一些程序的监控日志,都是属于过了一定的时间就可以被覆盖的数据。?修改数据表名?db.Account.renameCollection(Account1){?ok?:?1?}?数据表帮助主题help?db.Account.help()DBCollection?help????????db.Account.find().help()?-?show?DBCursor?help????????db.Account.count()????????db.Account.dataSize()????????db.Account.distinct(?key?)?-?eg.?db.Account.distinct(?x?)????????db.Account.drop()?drop?the?collection????????db.Account.dropIndex(name)????????db.Account.dropIndexes()????????db.Account.ensureIndex(keypattern[,options])?-?options?is?an?object?with?these?possible?fields:?name,?unique,?dropDups????????db.Account.reIndex()????????db.Account.find([query],[fields])?-?query?is?an?optional?query?filter.?fields?is?optional?set?of?fields?to?return.??????????????????????????????????????????????????????e.g.?db.Account.find(?{x:77}?,?{name:1,?x:1}?)????????db.Account.find(...).count()????????db.Account.find(...).limit(n)????????db.Account.find(...).skip(n)????????db.Account.find(...).sort(...)????????db.Account.findOne([query])????????db.Account.findAndModify(?{?update?:?...?,?remove?:?bool?[,?query:?{},?sort:?{},?new:?false]?}?)????????db.Account.getDB()?get?DB?object?associated?with?collection????????db.Account.getIndexes()????????db.Account.group(?{?key?:?...,?initial:?...,?reduce?:?...[,?cond:?...]?}?)????????db.Account.mapReduce(?mapFunction?,?reduceFunction?,?optional?params?)????????db.Account.remove(query)????????db.Account.renameCollection(?newName?,?dropTarget?)?renames?the?collection.????????db.Account.runCommand(?name?,?options?)?runs?a?db?command?with?the?given?name?where?the?first?param?is?th
显示全部
相似文档