node.js学习(二十三、mongodb命令)
2017-04-03 21:32
423 查看
1.打开mongodb shell窗口
[root@iZ94b9jaqbfZ bin]# cd /usr/mongodb-linux-x86_64-3.4.3/bin [root@iZ94b9jaqbfZ bin]# ls bsondump mongod mongodump mongofiles mongooplog mongoreplay mongos mongotop mongo mongodb.conf mongoexport mongoimport mongoperf mongorestore mongostat [root@iZ94b9jaqbfZ bin]# ./mongo MongoDB shell version v3.4.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.3 Server has startup warnings: 2017-04-03T20:21:01.683+0800 I STORAGE [initandlisten] 2017-04-03T20:21:01.683+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2017-04-03T20:21:01.683+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2017-04-03T20:21:03.058+0800 I CONTROL [initandlisten] 2017-04-03T20:21:03.059+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-04-03T20:21:03.059+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-04-03T20:21:03.059+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-04-03T20:21:03.059+0800 I CONTROL [initandlisten] 2017-04-03T20:21:03.062+0800 I CONTROL [initandlisten] 2017-04-03T20:21:03.062+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files. >
2.创建使用数据库
use DBNAME 当库不存在时会创建
> use test switched to db test > show dbs admin 0.000GB local 0.000GB
show dbs查看所有数据库,但是新创建的数据库不会被列出,当其中至少有一条数据时才回被列出。
> db.abc.insert({"key":"test","val":"这是一条测试数据"}) WriteResult({ "nInserted" : 1 }) > show dbs admin 0.000GB local 0.000GB test 0.000GB
插入数据后正常显示
3.删除数据库
db.dropDatabase()删除数据库
> db.dropDatabase() { "dropped" : "test", "ok" : 1 }
db.collection.drop() 删除某一集合数据
> db.abc.drop() true
3.向集合中插入数据(对象,不能插入字符串、数字等)
> db.abc.insert({"key":"test","val":"这是一条测试数据"}) WriteResult({ "nInserted" : 1 }) > db.abc.insert({"key":"test","val":"这是一条测试数据"}) WriteResult({ "nInserted" : 1 }) > db.abc.find() { "_id" : ObjectId("58e24b2ad14f02725996ff07"), "key" : "test", "val" : "这是一条测试数据" } { "_id" : ObjectId("58e24bc2d14f02725996ff08"), "key" : "test", "val" : "这是一条测试数据" }
4.查询、更新、删除
> db.abc.find() { "_id" : ObjectId("58e24b2ad14f02725996ff07"), "key" : "test", "val" : "这是一条测试数据" } { "_id" : ObjectId("58e24bc2d14f02725996ff08"), "key" : "test", "val" : "这是一条测试数据" } > db.abc.find({ "_id" : ObjectId("58e24b2ad14f02725996ff07")}) { "_id" : ObjectId("58e24b2ad14f02725996ff07"), "key" : "test", "val" : "这是一条测试数据" } > db.abc.update({ "_id" : ObjectId("58e24b2ad14f02725996ff07")},{$set:{'val':"aaa"}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.abc.find({ "_id" : ObjectId("58e24b2ad14f02725996ff07")}) { "_id" : ObjectId("58e24b2ad14f02725996ff07"), "key" : "test", "val" : "aaa" } > db.abc.remove({ "_id" : ObjectId("58e24b2ad14f02725996ff07")}) WriteResult({ "nRemoved" : 1 }) > db.abc.find({ "_id" : ObjectId("58e24b2ad14f02725996ff07")}) > db.abc.find() { "_id" : ObjectId("58e24bc2d14f02725996ff08"), "key" : "test", "val" : "这是一条测试数据" }
相关文章推荐
- 从零开始学习Node.js例子八 使用SQLite3和MongoDB
- MongoDB for node.js developers 七周学习-最终测试小结(1)
- 学习用Node.js和Elasticsearch构建搜索引擎(2):一些检索命令
- nodejs+nginx+mongoDB部署项目学习笔记
- 学习用Node.js和Elasticsearch构建搜索引擎(6):实际项目中常用命令使用记录
- node.js在windows下的学习笔记(2)---简单熟悉一些命令
- 使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用的学习过程(一)
- 学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch
- 使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用的学习过程(三)
- node.js学习第3天,mongos 连接MongoDB
- node.js学习笔记(4)_极客学院_MongoDB的使用
- Docker学习之——Node.js+MongoDB+Nginx环境搭建(一)
- node.js学习(二十二、mongodb安装)
- Node.js知识学习之——Node.js and MongoDB – Getting started with MongoJS
- node.js学习笔记之常用命令
- node.js学习笔记(5)--MongoDB下载及安装
- [MongoDB学习笔记-02] Node.js连接MongoDB的两种方法
- Node.js + MongoDB 后端学习笔记
- 从零开始学习Node.js系列教程之SQLite3和MongoDB用法分析