MongoDB simple command
来源:互联网 发布:批处理卸载软件 编辑:程序博客网 时间:2024/05/23 00:27
1. download free Mongodb from https://www.mongodb.com/download-center#community, I use windows version
2. install mongodb
3. start mongodb
D:\dev\MongoDB\bin>mongod
4. use command line
D:\dev\MongoDB\bin>mongo
5. list current databases
>show dbs
>show databases
6. create a database named 'lyexnode'
use lyexnode
7. list tables
>show tables
>show collections
8. list users
>show users
9. list roles
>show roles
https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/#mongo-shell-javascript-file
10. execute users.js file
db = connect("localhost:27017/lyexnode");cursor = db.users.find();
while ( cursor.hasNext() ) {
printjson( cursor.next() );
}
D:\dev\MongoDB\bin>mongo localhost:27017/lyexnode users.js
D:\dev\MongoDB\bin>mongo users.js>load("users.js")
11. find data in table/document
a. query, return all of the columns
db.users.findOne({"name":"admin"})
b. query with specified return columns. "_id" is returned by default. It has to be specified as 0 explicitly
12. insert/update data to document
db.userInfo.insertOne( { name: "sue", age: 26, status: "pending" })
db.userInfo.insert( { name: "sue", age: 26, status: "A" })
db.userInfo.insertMany( [ { name: "sue", age: 26, status: "pending" }, { name: "bob", age: 25, status: "enrolled" }, { name: "ann", age: 28, status: "enrolled" } ])
db.userInfo.updateOne( { age: { $lt: 18 } }, { $set: { status: "reject" } })
db.userInfo.updateMany( { age: { $lt: 18 } }, { $set: { status: "reject" } })
db.userInfo.replaceOne( { name: "sue" }, { name: "amy", age : 25, score: "enrolled" })
13.delete
db.userInfo.deleteOne( { status: "reject" })
db.userInfo.deleteMany( { status: "reject" })
db.userInfo.remove( { status: "D" })
- MongoDB simple command
- simple command of linux
- mongodb simple auth
- linux command "ls" simple implementation
- Unix command - Awk simple instruction
- Simple and powerful command of Microsoft Windows
- 25 simple examples of Linux find command
- 【MongoDB】Serveral common command of MongoDb
- Simple Automated Backups for MongoDB Replica Sets
- Mongodb源码分析--Command体系架构
- Mongodb源码分析--Command体系架构
- Invalid command: files\mongoDB\log\log.txt
- Mongodb源码分析--Command体系架构
- run command from Java driver for MongoDB
- Spring-boot实例学习之Simple Command line application
- Simple example - Node.js, Restify, MongoDb and Mongoose
- MongoDB的golang驱动安装 + 首次调用Mongo Command。
- simple
- 机器学习笔记(一):绪论
- Android浏览图片,点击放大至全屏效果(包含点击前位置到全屏的动画)
- 第一个爬虫:爬糗事百科笑话
- Canvas——路径使用的一些感悟
- G.711编解码原理
- MongoDB simple command
- navigationBar色差解决
- 第十一周实践项目4-教师兼干部类
- Linux下GDB调试工具使用
- Java中获取文件大小的正确方法
- Android Dev Intro - Some Concepts
- Android 序列化
- Think安装redis 去除index
- iOS UICollectionView XIB