Home Database Mysql Tutorial mongoDB安装启动对文档的增删改操作

mongoDB安装启动对文档的增删改操作

Jun 07, 2016 pm 04:04 PM
mongodb start up Install operate document

把mongodb解压缩完的bin路径加到环境变量 创建a.bat和b.bat文件: a.bat内容: mongod --dbpath F:\MongoData b.bat内容: mongo 127.0.0.1:27017/admin a.bat是启动mongodb服务器,--dbpath用来指定数据的存储路径 b.bat是启动mongo shell(即:js 引擎),admin

把mongodb解压缩完的bin路径加到环境变量

创建a.bat和b.bat文件:

a.bat内容:

mongod --dbpath F:\MongoData

b.bat内容:

mongo 127.0.0.1:27017/admin

a.bat是启动mongodb服务器,--dbpath用来指定数据的存储路径

b.bat是启动mongo shell(即:js 引擎),admin用来指定哪个数据库

启动a.bat,看到

2014-10-14T22:35:48.734+0800 [initandlisten] waiting for connections on port 270
17

说明ok了

窗口不要关,那个是mongo的服务器

再启动b.bat:

MongoDB shell version: 2.6.5
connecting to: 127.0.0.1:27017/admin

看到这个说明,mongo shell已经启动,2.6.5中间的6是偶数,代表是稳定的release版本,奇数代表开发版

一点点简单的小命令:

创建数据库:

> use foobar
switched to db foobar

此时不做任何操作或者关闭窗口,该数据库立即消失

> db.persons.insert({name:"uspcat"})
WriteResult({ "nInserted" : 1 })

插入一条记录,该persons文档就会在foobar数据库中存在

显示有哪些数据库的命令:

> show dbs
admin (empty)
foobar 0.078GB
local 0.078GB

显示有哪些集合命令:

> show collections
persons
system.indexes

查找persons文档记录的命令:

> db.persons.find()
{ "_id" : ObjectId("543d357df0b430df52a3ef24"), "name" : "uspcat" }

也可以使用findOne()查找第一条记录:

> db.persons.findOne()
{ "_id" : ObjectId("543d357df0b430df52a3ef24"), "name" : "uspcat" }

插入记录:

> db.persons.insert({name:"extjs4.0"})
WriteResult({ "nInserted" : 1 })
> db.persons.find()
{ "_id" : ObjectId("543d357df0b430df52a3ef24"), "name" : "uspcat" }
{ "_id" : ObjectId("543d370df0b430df52a3ef25"), "name" : "extjs4.0" }

更新操作:

> var p = db.persons.findOne()
> p
{ "_id" : ObjectId("543d357df0b430df52a3ef24"), "name" : "uspcat" }
> db.persons.update(p,{name:"uspcat2"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> var p = db.persons.findOne()
> p
{ "_id" : ObjectId("543d357df0b430df52a3ef24"), "name" : "uspcat2" }

可以声明var的原因,是因为mongo shell就是个js 引擎

更新操作最好是使用查询器和修改器:

> db.persons.update({name:"extjs4.1"},{$set:{age:1,name:"tom2"}});

这样把第二条记录的name改成了tom2,同时增加了age:1的Bson

删除操作:

> db.persons.remove({name:"tom2"})
WriteResult({ "nRemoved" : 1 })

ctrl+c退出mongo shell引擎

ctrl+c退出mongod服务器,Y命令终止批处理

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Jun 25, 2024 pm 07:09 PM

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

What is the use of net4.0 What is the use of net4.0 May 10, 2024 am 01:09 AM

.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.

golang framework document usage instructions golang framework document usage instructions Jun 05, 2024 pm 06:04 PM

How to use Go framework documentation? Determine the document type: official website, GitHub repository, third-party resource. Understand the documentation structure: getting started, in-depth tutorials, reference manuals. Locate the information as needed: Use the organizational structure or the search function. Understand terms and concepts: Read carefully and understand new terms and concepts. Practical case: Use Beego to create a simple web server. Other Go framework documentation: Gin, Echo, Buffalo, Fiber.

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

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

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

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

Navicat's method to view MongoDB database password Navicat's method to view MongoDB database password Apr 08, 2025 pm 09:39 PM

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).

How to find documentation and tutorials for a specific framework? How to find documentation and tutorials for a specific framework? Jun 02, 2024 am 10:17 AM

How to find documentation and tutorials for a specific framework: Visit the official framework website and look for the "Documentation" or "Tutorials" tab. Check the framework's GitHub repository or third-party website for community-contributed documentation. Use search engines, video sharing platforms, and online communities to find online tutorials.

Major update of Pi Coin: Pi Bank is coming! Major update of Pi Coin: Pi Bank is coming! Mar 03, 2025 pm 06:18 PM

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

See all articles