mongodb download, configure the environment variables and other operations

MongoDB Download

      Address: https://www.mongodb.com/download-center#community

 

  • MongoDB for Windows 64-bit  for 64-bit Windows Server 2008 R2, Windows 7, and the latest version of the Window System.
  • MongoDB for Windows 32-bit  for 32-bit Window System and the latest Windows Vista. MongoDB the database system up to 32 2GB.
  • MongoDB for Windows 64-bit Legacy  for 64-bit Windows Vista, Windows Server 2003, and Windows Server 2008.

 

 

The first installation: complete

 

 

The default installation point has been determined complete

 

After the mounting operation:

1. configuration environment variable (can open cmd mongodb run directly from the desktop)

This address will be copied: C: \ Program Files \ MongoDB \ Server \ 3.2 \ bin

This opens the desktop computer ---- "Right Properties -----" Advanced System Configuration --- "environment variable configuration -------" find the path system variable configuration variables ------ "New Tag copy the address into it.

 

 

 

 

 

 

Operating mongodb

1. Start Mongodb server --------------------------

If you do not configure the environment variables on the implementation of the following command:

You must perform mongod.exe files from the bin directory in the directory MongoDB MongoDB server running from the command prompt.

C:\mongodb\bin\mongod --dbpath c:\data\db

配置了黑窗口直接执行一下操作:(设置全局变量的好处)

mongod --dbpath c:\data\db

 

2.操作mongodb库

必须启动服务,否则无法操作。

以下操作数据库的操作:

cmd

mongo(进入交互模式)

show dbs 列出所有数据库
 
use <数据库名称> 创建/切换数据库
 
db 查看当前使用的那个数据库
 
db.createCollection('表的名称') 创建一张表
 
db.getCollectionNames() 查看当前数据库所有的表
 
db.getCollection('表名称') 使用某一张表
 
db.<表名>.save({})
 
db.<表名>.remove({key:val})
db.<表名>.r emove({})
 
db.<表名>.update({key:val},{$set:{key:val,key:val......}})
db.<表名>.update({key:val},{$inc:{age:-10}})
 
db.<表名>.find() 查找所有
 
db.<表名>.find({key:val}) 查找指定的数据
 
db.<表名>.find({key:{$lt:19}}) 小于19
db.<表名>.find({key:{$lte:19}}) 小于等于19
db.<表名>.find({key:{$gt:19}}) 大于19
db.<表名>.find({key:{$gte:19}}) 大于等于19
db.<表名>.find({key:{$gte:19,$lte:32}}) 大于等于19 小于等于32
 
db.<表名>.find({name:/王/}) 模糊查询
 
db.<表名>.find({name:/^王/}) 模糊查询
 
db.<表名>.find({name:/王$/}) 模糊查询
 
db.<表名>.find({},{name:1,age:1,_id:0}) 查看指定列
显示需要的 1为需要 0 为不需要
 
db.<表名>.find().sort({age:1}) 1正序 -1倒序
 
db.<表名>.find().limit(2) 显示多少条数据
 
db.<表名>.find().skip(2) 跳过多少条数据
 
db.<表名>.find()skip(n).limit(n) 分页
 
db.<表名>.findOne() 只查找一条数据
 
db.<表名>.find().count() 查看表中有多少条数据

 

Guess you like

Origin www.cnblogs.com/xiaoniaohhl/p/11293808.html