MongoDB学习(三)MongoDB shell命令行的使用
首先要启动MongoDB shell工具,即bin下的mongo.exe 常用shell命令如下: 1、查询本地所有数据库名称 show dbs; 2、切换至指定数据库环境(若无指定的数据库,则创建新的库) use dbtest; 切换至dbtest库或创建名为dbtest的库 3、查询当前库下的所有聚集集合co
首先要启动MongoDB shell工具,即bin下的mongo.exe
常用shell命令如下:
1、查询本地所有数据库名称
> show dbs;
2、切换至指定数据库环境(若无指定的数据库,则创建新的库)
> use dbtest;
切换至dbtest库或创建名为dbtest的库
3、查询当前库下的所有聚集集合collection(相当于table)
www.2cto.com
> show collections;
4、创建聚集集合
> db.createCollection('employee');
创建了一个名为'employee'的聚集集合
5、插入数据
> db.employee.insert({'uname':'teddy','age':24,'salary':11000});
往'employee'聚集集合中插上一条数库,name为'teddy',age为'24',salary为'11000'
6、查询聚集集合中数据条数
> db.employee.count();
7、查询age为了23的数据
> db.employee.find({"age":23});
8、查询salary大于5000的数据
www.2cto.com
> db.employee.find({salary:{$gt:5000}});
9、查询age小于23,salary大于8000的数据
> db.employee.find({age:{$lt:24}},{salary:{$gt:8000}});
10、查询salary小于4000或salary大于20000的数据
> db.employee.find({$or: [{salary: {$lt:4000}}, {salary: {$gt:20000}}]});
11、查询指定列的数据
> db.employee.find({},{age:1,salary:1});
1表示显示此列的意思,也可以用true表示
12、查询uname中包含'e'的数据
> db.employee.find({uname:/e/});
13、查询以a打头的数据
> db.employee.find({uname:/^a/});
14、查询age列数据,并去掉重复数据
> db.employee.distinct('age');
15、查询前10条数据
> db.employee.find().limit(10);
16、查询1条以后的所有数据
> db.employee.find().skip(1);
17、查询第一条数据
> db.employee.findOne();
18、查询结果集的记录数(查询salary小于4000或大于10000的记录数)
db.employee.find({$or: [{salary: {$lt:4000}}, {salary: {$gt:10000}}]}).count();
19、按salary升序排序
> db.employee.find().sort({salary:1});
按照salary字段升序排序
20、降序 www.2cto.com
> db.employee.find().sort({salary:-1});
按照salary字段降序排序
21、根据uname修改age
> db.employee.update({uname:'jim'},{$set:{age:22}},false,true);
db.collection.update( criteria, objNew, upsert, multi )
criteria : update的查询条件,类似sql update查询内where后面的
objNew : update的对象和一些更新的操作符(如$,$inc...)等,也可以理解为sql update查询内set后面的
upsert : 如果不存在update的记录,是否插入objNew,true为插入,默认是false,不插入。
multi : mongodb默认是false,只更新找到的第一条记录,如果这个参数为true,就把按条件查出来多条记录全部更新。
22、将指定uname的age字段增加5
> db.employee.update({uname:'jim'},{$inc:{age:5}},false,true);
将uname为‘jim’的age字段加5
23、删除uname为'rose'的数据
> db.employee.remove({uname:'rose'});
24、集合collection重命名 www.2cto.com
> db.employee.renameCollection('t_emp');
将employee集合重命名为't_emp'
25、删除集合
> db.emp_test.drop();
删除名为'emp_test'的集合
26、删除当前数据库
> db.dropDatabase();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy

The MongoDB database is known for its flexibility, scalability, and high performance. Its advantages include: a document data model that allows data to be stored in a flexible and unstructured way. Horizontal scalability to multiple servers via sharding. Query flexibility, supporting complex queries and aggregation operations. Data replication and fault tolerance ensure data redundancy and high availability. JSON support for easy integration with front-end applications. High performance for fast response even when processing large amounts of data. Open source, customizable and free to use.
