mongoDB--简单操作

1.打开控制台

1.cd mongodb-osx-x86_64-2.6.9/bin
2../mongod  mongodb 不能关闭控制台

2.新开控制台

1.cd mongodb-osx-x86_64-2.6.9/bin
2.登录管理mongodb,./mongo

3基本命令:

show dbs   查看现有数据库

4.use +数据库名字(自动创建)

5.show collections (展示数据库所有的集合<对应于关系型数据库的表>)

6· db.loopbacktest.find().pretty() (查询表中所有数据findone是查一条)

7.其他命令

LiuHaiYangdeMacBook-Pro:bin PersnHome$ ./mongo
MongoDB shell version: 2.6.9
connecting to: test
Server has startup warnings: 
2016-05-14T17:40:19.697+0800 [initandlisten] 
2016-05-14T17:40:19.697+0800 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> show dbs
admin     0.078GB
hyt_zsyy  0.078GB
local     0.078GB
> use hyt_zsyy
switched to db hyt_zsyy
> show collections
admins
doctor_schedules
hospitals
registrations
system.indexes
users
verify_codes
> 
> db.users.
db.users.aggregate(                  db.users.getSplitKeysForChunks(
db.users.clean(                      db.users.getWriteConcern(
db.users.constructor                 db.users.group(
db.users.convertToCapped(            db.users.groupcmd(
db.users.convertToSingleObject(      db.users.hasOwnProperty(
db.users.copyTo(                     db.users.help(
db.users.count(                      db.users.indexStats(
db.users.createIndex(                db.users.initializeOrderedBulkOp(
db.users.dataSize(                   db.users.initializeUnorderedBulkOp(
db.users.diskStorageStats(           db.users.insert(
db.users.distinct(                   db.users.isCapped(
db.users.drop(                       db.users.mapReduce(
db.users.dropIndex(                  db.users.pagesInRAM(
db.users.dropIndexes(                db.users.propertyIsEnumerable(
db.users.ensureIndex(                db.users.prototype
db.users.exists(                     db.users.reIndex(
db.users.find(                       db.users.remove(
db.users.findAndModify(              db.users.renameCollection(
db.users.findOne(                    db.users.runCommand(
db.users.getCollection(              db.users.save(
db.users.getDB(                      db.users.setSlaveOk(
db.users.getDiskStorageStats(        db.users.setWriteConcern(
db.users.getFullName(                db.users.shellPrint(
db.users.getIndexKeys(               db.users.stats(
db.users.getIndexSpecs(              db.users.storageSize(
db.users.getIndexStats(              db.users.toLocaleString(
db.users.getIndexes(                 db.users.toString(
db.users.getIndices(                 db.users.tojson(
db.users.getMongo(                   db.users.totalIndexSize(
db.users.getName(                    db.users.totalSize(
db.users.getPagesInRAM(              db.users.unsetWriteConcern(
db.users.getPlanCache(               db.users.update(
db.users.getQueryOptions(            db.users.validate(
db.users.getShardDistribution(       db.users.valueOf(
db.users.getShardVersion(            db.users.verify(
db.users.getSlaveOk(
> db.users.find();
{ "_id" : ObjectId("5732ffadefff83e1117de101"), "password_original" : "test", "password" : "test", "name" : "test", "deleted_at" : null, "updated_at" : ISODate("2016-05-11T09:47:25.143Z"), "created_at" : ISODate("2016-05-11T09:47:25.143Z"), "patient" : [ { "_id" : ObjectId("5732ffadefff83e1117de102"), "idcard" : "653130199201141458", "phone" : "18612233895", "name" : "test" } ], "idcard" : "653130199201141458", "address" : "", "email" : "", "phone" : "18612233895", "__v" : 0 }
{ "_id" : ObjectId("573427653baecec708a748d6"), "password_original" : "123456", "password" : "e10adc3949ba59abbe56e057f20f883e", "name" : "kkk", "deleted_at" : null, "updated_at" : ISODate("2016-05-12T06:49:09.038Z"), "created_at" : ISODate("2016-05-12T06:49:09.038Z"), "patient" : [ { "name" : "kkk", "phone" : "18847451913", "idcard" : "511523198702112410", "_id" : ObjectId("573427653baecec708a748d7") } ], "idcard" : "511523198702112410", "address" : "", "email" : "", "phone" : "18847451913", "__v" : 0, "weichatID" : "18847451913", "SickID" : "6001491388" 
303724147}
> db.users.find().pretty;
function (){
    this._prettyShell = true;
    return this;
}
> use new_db
switched to db new_db
> db.createUser({user:'haiyang',pwd:'haiyang',roles:[{role:'dbOwner',db:'new_db'}]});
Successfully added user: {
    "user" : "haiyang",
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "new_db"
        }
    ]
}
> db.auth('haiyang','haiyang')
1
> show dbs
admin     0.078GB
hyt_zsyy  0.078GB
local     0.078GB
new_db    (empty)
> 
> use hyt_rmyy
switched to db hyt_rmyy
> 
> 
> 
> use hyt_rmyy
switched to db hyt_rmyy
> 
> db.createUser({"user":"hyt_rmyy","pwd":"hyt_rmyy_pw",roles:[{"role":"dbOwner","db":"hyt_rmyy"}]})
Successfully added user: {
    "user" : "hyt_rmyy",
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "hyt_rmyy"
        }
    ]
}
> 
> 
阅读更多
版权声明:欢迎转载! https://blog.csdn.net/liuhaiyanga/article/details/52367348
文章标签: 数据库 mongodb
个人分类: mongoDB
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

mongoDB--简单操作

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭