Home > Web Front-end > JS Tutorial > body text

Introduction to the installation and basic operation of Mongodb in Node

一个新手
Release: 2017-09-25 10:45:27
Original
1286 people have browsed it

1. Install mongodb

brew install mongodb
Copy after login

2. Database configuration

   1)vim ~/.bash_profile 
   2)立刻生效   source .bash_profile   # mongod db
   export PATH=/usr/local/Cellar/mongodb/3.4.9/bin:${PATH}
Copy after login

3. Open mongoldb

  1) sudo mongod  // 开启服务
  2) mongo        // 链接mongodb
Copy after login

4. Basic database operations

  1)  sho abs;  // 显示数据库
  2)use userinfo  //如果有则切换到userinfo数据库,如果没有就创建userinfo
  3)  db  //返回userinfo,表示当前userinfo处于准备状态
  4) db.users.insert({username:'admin',password:'123'})  //向userinfo中的users集合插入一条数据。如果有合集users则向该集合插入数据,如果没有,则先创建users集合,再插入数据
  5)db.users.find().pretty()  //显示users集合中的数据,pretty()是格式化
  6)db.users.remove({name:'xxx'})  //删除name为'xxx'的记录 7)db.users.remove({})  //删除users集合中的所有数据 8)db.users.drop()  //删除users集合 9)db.users.findOne({name:'xxx'})   //查询name为'xxx'的记录,只返回遇到的第一条记录 10)db.users.find()  //返回所有name为'xxx'的记录
Copy after login

5. Close the database:
Execute the following command on the command line

use admin;
db.shutdownServer();
Copy after login

The above is the detailed content of Introduction to the installation and basic operation of Mongodb in Node. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template