• mac 安装配置使用 mongoldb


    mac 安装配置使用 mongoldb

    安装和配置

    brew install mongos
    brew install mongo
    	
    # 密码就是用户的密码
    # 配置数据文件 //如果不配置会出现错误62
    sudo rm -rf /data/db
    sudo mkdir data/db
    sudo chown your_user_name /data/db
    	
    # 启动服务端
    sudo mongod 
    # 建议
    sudo mongod &
    	
    # 启动客户端
    sudo mongo
    

    进入mongo之后

    • 显示有什么数据库

      > show dbs
      admin   0.000GB
      config  0.000GB
      local   0.000GB
      
    • 创建/使用一个数据库 use的作用:数据库存在就使用,没有就创建

      > use test2019
      switched to db test2019
      > db
      test2019
      
    • 创建数据表

      > db.createCollection("department")
      { "ok" : 1 }
      
      
    • 插入数据

      > db.department.insert({'name': 'Research and Development Department'})
      WriteResult({ "nInserted" : 1 })
      > db.department.insert({'name': 'Hr'})
      WriteResult({ "nInserted" : 1 })
      > db.department.insert({'name': 'Market'})
      WriteResult({ "nInserted" : 1 })
      > db.department.insert({'name': 'Accounting'})
      WriteResult({ "nInserted" : 1 })
      > db.department.insert({'name': 'Test', 'employee': 10 })
      WriteResult({ "nInserted" : 1 })
      
    • 查找数据

      > db.department.find()
      { "_id" : ObjectId("5c358f9e5f9d20c5d1020089"), "name" : "Research and Development Department" }
      { "_id" : ObjectId("5c358fa75f9d20c5d102008a"), "name" : "Hr" }
      { "_id" : ObjectId("5c358fae5f9d20c5d102008b"), "name" : "Market" }
      { "_id" : ObjectId("5c358fc85f9d20c5d102008c"), "name" : "Accounting" }
      { "_id" : ObjectId("5c3591e25f9d20c5d102008d"), "name" : "Test", "employee" : 10 }
      
      
    • 条件查询

      # 这种逗号隔开 表示 与
      db.collection.find({'key1': condition1, 'key2': condition2})
      

      # $in 和 $or 比较接近mysql里的 或
      > db.department.find({'name': 'Hr' })
      { "_id" : ObjectId("5c358fa75f9d20c5d102008a"), "name" : "Hr" }
      # in
      > db.department.find({'name':{"$in":['Accounting', 'Hr']}})
      { "_id" : ObjectId("5c358fa75f9d20c5d102008a"), "name" : "Hr" }
      { "_id" : ObjectId("5c358fc85f9d20c5d102008c"), "name" : "Accounting" }
      # or 
      # pretty的作用是自动换行
      > db.department.find({'$or': [{'name': 'Hr'}, {'employee':10}]}).pretty()
      { "_id" : ObjectId("5c358fa75f9d20c5d102008a"), "name" : "Hr" }
      {
      	"_id" : ObjectId("5c3591e25f9d20c5d102008d"),
      	"name" : "Test",
      	"employee" : 10
      }
      

      大于小于

      # 在mysql里用between..and..或者 >、>=、<、<=来查询指定的范围,
      # 但是mongodb有自己的语法。用 "$gt" 、"$gte"、 "$lt"、 "$lte"
      # 分别对应">"、 ">=" 、"<" 、"<=",组合起来可以进行范围的查找。
      > db.department.find({'employee': {'$gte' : 5}})
      { "_id" : ObjectId("5c3591e25f9d20c5d102008d"), "name" : "Test", 	"employee" : 10 }
      
  • 相关阅读:
    asp.net tutorial(http://www.cnblogs.com/mqingqing123/archive/2006/04/16/376358.html)
    CSS五日教程 (reference to http://www.tuqiu.com/study/css/day1_1.php)
    CSS教程 http://www.lnnu.edu.cn/dandu/hqcy/internet/jiaocheng/css/css.htm
    关于Spoolsv.exe
    理解MVC
    Design Patterns(十五):Command PatternVB代码
    Design Patterns(十六):Interpreter PatternVB代码
    Design Patterns(十三):Proxy PatternVB代码
    Design Patterns(二十):Observer PatternVB代码
    【转】VB中动态编程的技巧和挑战:多重分派
  • 原文地址:https://www.cnblogs.com/wangjiale1024/p/10244358.html
Copyright © 2020-2023  润新知