当前位置:网站首页>MongoDB是什么,怎么用?
MongoDB是什么,怎么用?
2022-08-08 10:09:00 【51CTO】
MongoDB是一款为web应用程序和互联网基础设施设计的数据库管理系统,简单来说,MongoDB就是数据库,是NoSQL类型的数据库。那么,我们要怎么使用MongoDB呢?
1.切换数据库
use dba
2.插入语法
(1)db.users.insert({username:"smith"})
(2)db.users.save({username:"smith"})
3.查找语法
(1)db.users.find()
(2)db.users.count()
4.更新语法
(1)db.users.update({username:"smith"},{$set:{country:"Canada"}}) ;
(2)//把用户名为smith的用户的国家改成Canada ;
(3)db.users.update({username:"smith"},{$unset:{country:1}}) ;
(4)//把用户名为smith的用户的国家字段给移除 ;
(5)db.users.update({username:"jones"},{$set:{favorites:{movies:
["casablance","rocky"]}}}) ;
(6)//这里主要体现多值修改,在favorties字段中添加多个值 ;
(7)db.users.update({"favorites.movies":"casablance"},{$addToSet:{favorites.
movies:"the maltese"}},false,true)
(8)//多项更新
5.删除语法
(1)db.foo.remove() //删除所有数据
(2)db.foo.remove({favorties.cities:"cheyene"}) //根据条件进行删除
(3)db.drop() //删除整个集合
6.索引相关语法
(1)db.numbers.ensureIndex({num:1})
(2)//创建一个升序索引
(3)db.numbers.getIndexes()
(4)//获取全部索引
7.基本管理语法
(1)show dbs ;
(2)//查询所有数据库 ;
(3)show collections ;
(4)//显示所有表 ;
(5)//显示数据库状态信息;
(6)db.numbers.stats() ;
(7)//显示集合表状态信息 ;
(8)db,shutdownServer() ;
(9)//停止数据库 ;
(10)db.help() ;
(11)//获取数据库操作命令 ;
(12)db.foo.help();
(13)//获取表操作命令 ;
(14)tab 键 //能自动帮我们补全命令
边栏推荐
猜你喜欢
随机推荐
Dubins curve study notes and related thinking
有哪些典型的列存储数据库呢?
在mysql中,存储过程中参数为中文 乱码解决方案
In the.net core, the use of c # realize fastdfs batch file upload more
文档数据库于键值数据库有什么不同吗?
Redis是持久化键值数据库嘛?
HMS Core分析服务智能运营6.5.1版本上线
.net开发中,C# DateTime.Now 取出的时间含有星期解决办法
中原银行实时风控体系建设实践
VMWare Esxi 虚拟系统数据存储扩容(增加容量)的简明教程
NoSQL的意思就是就是不使用SQL吗?
推荐100首好听英文歌
To make people's consumption safer, more assured and more satisfied
xgboost 加速
Code implementation of various kinds of attention
Bytes and Characters and Common Encodings
软件测试的分类
使用.NET简单实现一个Redis的高性能克隆版(三)
【Collection】3. Wallpaper collection
PCBA电路板为什么需要使用三防漆,有何作用?