zoukankan      html  css  js  c++  java
  • mac 安装mongodb

    很简单:

    brew update

    brew install mongodb

    耐心等待安装完毕,出现提示:

    To have launchd start mongodb now and restart at login:
      brew services start mongodb  --后台启动
    Or, if you don't want/need a background service you can just run:
      mongod --config /usr/local/etc/mongod.conf   --临时启动

    安装就完事儿了。

    使用:shell控制台  >mongo 即可。

    常用命令:

    > show dbs

    admin  0.000GB

    local  0.000GB

    test   0.000GB

     

    > db

    test

     

    > db.test.insert({title:'firstOne',age:10})

    WriteResult({ "nInserted" : 1 })

     

     

    > db.test.insert({title:'second',name:20,sex:'woman'})

    WriteResult({ "nInserted" : 1 })

     

    > db.test.find()

    { "_id" : ObjectId("58b281b13dbc5b19bfa74e7e"), "title" : "firstTest", "name" : "liuyang", "age" : 10 }

    { "_id" : ObjectId("58b282273dbc5b19bfa74e7f"), "title" : "firstOne", "age" : 10 }

    { "_id" : ObjectId("58b282593dbc5b19bfa74e80"), "title" : "second", "name" : 20, "sex" : "woman" }

     

    > db.test.find()

    { "_id" : ObjectId("58b281b13dbc5b19bfa74e7e"), "title" : "firstTest", "name" : "liuyang", "age" : 10 }

    { "_id" : ObjectId("58b282273dbc5b19bfa74e7f"), "title" : "firstOne", "age" : 10 }

    { "_id" : ObjectId("58b282593dbc5b19bfa74e80"), "title" : "second", "name" : 20, "sex" : "woman" }

    > db.test.find().pretty()

    {

    "_id" : ObjectId("58b281b13dbc5b19bfa74e7e"),

    "title" : "firstTest",

    "name" : "liuyang",

    "age" : 10

    }

    {

    "_id" : ObjectId("58b282273dbc5b19bfa74e7f"),

    "title" : "firstOne",

    "age" : 10

    }

    {

    "_id" : ObjectId("58b282593dbc5b19bfa74e80"),

    "title" : "second",

    "name" : 20,

    "sex" : "woman"

    }

    > db.test.find({title:'firstOne'}).pretty()

    {

    "_id" : ObjectId("58b282273dbc5b19bfa74e7f"),

    "title" : "firstOne",

    "age" : 10

    }

     

    > db.test.find({$or:[{title:'firstOne'},{sex:'woman'}]}).pretty()

    {

    "_id" : ObjectId("58b282273dbc5b19bfa74e7f"),

    "title" : "firstOne",

    "age" : 10

    }

    {

    "_id" : ObjectId("58b282593dbc5b19bfa74e80"),

    "title" : "second",

    "name" : 20,

    "sex" : "woman"

    }

     

    > db.test.find({age:{$gt:5}}).pretty()

    {

    "_id" : ObjectId("58b281b13dbc5b19bfa74e7e"),

    "title" : "firstTest",

    "name" : "liuyang",

    "age" : 10

    }

    {

    "_id" : ObjectId("58b282273dbc5b19bfa74e7f"),

    "title" : "firstOne",

    "age" : 10

    }

    >

    > db.test.find({title:'firstTest'},{name:1,_id:0}) --只返回指定字段 1 -show  0-hide

     

    >db.test.find().sort({age:0})

     

    > db.test.updateOne({title:'firstTest'},{$set:{age:30}})

     

     

  • 相关阅读:
    R语言nest_join()函数
    R语言行/列合并
    ffmpeg 命令将视频转化为图帧
    Natas Wargame Level20 Writeup(会话状态注入/篡改)
    vim简明教程--半小时从入门到精通
    笔记:Spring Cloud Hystrix 异常处理、缓存和请求合并
    【Ecstore2.0】导出问题解决(未导出或导出文件为0字节)
    Android Handler消息处理顺序分析
    着色器语言之变量类型
    Redis源码分析(十一)--- memtest内存检测
  • 原文地址:https://www.cnblogs.com/luoluoshidafu/p/6484148.html
Copyright © 2011-2022 走看看