MongoDB的使用
最近项目用到了mongoDB,最近类mongoDB的Nosql数据库也比较火爆,把这个写下来,便于自己回顾和大家学习. 在mongoDB中数据的关系是database,collection,document 放到关系型数据库里面就是库,表,数据. 1.在ubuntu下执行 sudo apt-get install mongo 安装mongo.
最近项目用到了mongoDB,最近类似mongoDB的Nosql数据库也比较火爆,把这个写下来,便于自己回顾和大家学习.
在mongoDB中数据的关系是database,collection,document 放到关系型数据库里面就是库,表,数据.
1.在ubuntu下执行 sudo apt-get install mongo 安装mongo.
2.输入mongo进入数据库.
查看集合(表) show collections;
查看student集合的数据
db.student.find();
db.student.find().forEach(printjson);
查看第三条到第六条记录
db.student.find().skip(2).limit(3);
db.student.find().forEach(printjson); ---以json格式查看记录
向student集合中插入数据
db.student.insert({name:"Jack",age:22,score:86});
删除某条数据
db.student.remove({name:"Jack"});
修改数据
db.student.update({name:"Tom"},{$set:{name:"Lubby"}});
条件查询:
db.student.find({score:{$gt:86}}); score>86
db.student.find({score:{$gte:86}}); score>=86
db.student.find({score:{$lt:100}}); score
db.student.find({score:{$lte:100}}); score
db.student.find({score:{$gt:87,$lt:100}}); 87 db.student.find({name:{$ne:"Lubby"}}); name != Lubby 显示某个字段存在的数据 db.student.find({name:{$exists:true}}); 查询不匹配 name=B*带头的记录 正则表达式匹配 排序 db.student.find().sort({score:1}); 按照score升序排序 db.student.find().sort({score:-1}); 按照score降序排序 还有一些类似分组查询的回头有时间再补上.
db.users.find({name: {$not: /^B.*/}});

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



BitgetLaunchpool is a dynamic platform designed for all cryptocurrency enthusiasts. BitgetLaunchpool stands out with its unique offering. Here, you can stake your tokens to unlock more rewards, including airdrops, high returns, and a generous prize pool exclusive to early participants. What is BitgetLaunchpool? BitgetLaunchpool is a cryptocurrency platform where tokens can be staked and earned with user-friendly terms and conditions. By investing BGB or other tokens in Launchpool, users have the opportunity to receive free airdrops, earnings and participate in generous bonus pools. The income from pledged assets is calculated within T+1 hours, and the rewards are based on

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

Sorting index is a type of MongoDB index that allows sorting documents in a collection by specific fields. Creating a sort index allows you to quickly sort query results without additional sorting operations. Advantages include quick sorting, override queries, and on-demand sorting. The syntax is db.collection.createIndex({ field: <sort order> }), where <sort order> is 1 (ascending order) or -1 (descending order). You can also create multi-field sorting indexes that sort multiple fields.

In the last week of June, all established Ethereum blue-chip NFT projects rebounded. CryptoPunks rebounded by 24%, BAYC rebounded by 30%, PudgyPenguins rebounded by 50%, and Azuki rebounded by 35%. Solana’s top brand MadLads also rose by 40%, and Bitcoin’s top projects NodeMonkes and BitcoinPuppets also rose by more than 20%. Is this a sign that NFT has bottomed out? The editor believes that it is too early to open the champagne at this time. However, we can first look ahead to July, which has already arrived, and see which NFT projects deserve our attention. AbstractChain (formerly Fra
