惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Secure Thoughts
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - Franky
有赞技术团队
有赞技术团队
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
NISL@THU
NISL@THU
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
W
WeLiveSecurity
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
O
OpenAI News
V
V2EX
AI
AI
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
G
GRAHAM CLULEY
月光博客
月光博客
T
Threatpost
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
Last Week in AI
Last Week in AI
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cloudbric
Cloudbric
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
N
News | PayPal Newsroom
Know Your Adversary
Know Your Adversary

Jay Zangwill

前端该如何选择图片的格式 移动端适配 扒一扒浏览器缓存机制 line-height和vertical-align采坑记 分享个人前端学习路线及面试经验 搜狗实习总结 vue-cli-multipage 记一次我看红宝书对继承加深的理解 四月北京面试之旅 几个让我印象深刻的面试题(二) 几个让我印象深刻的面试题(一) css盒模型与定位 javscript的数据类型 angular学习笔记(3) angular学习笔记(2) angular学习笔记(1) 初尝vue sass基础 hexo+github快速搭建个人博客
常用的mongodb命令
Jay Zangwill · 2017-04-10 · via Jay Zangwill

下面是一些我常用的mongodb命令,供自己备忘

  1. show dbs (列出所有数据库)
  2. use [database name] (数据库的切换)
  3. show collections (查看当前使用数据库有哪些表)
  4. db.[表名].find() (查找当前表下所有数据)
  5. db.[表名].findOne({‘key’:value}) (查找一条符合查询条件的数据)
  6. db.[表名].drop() (删除当前表)
  7. db.[表名].move({‘key’:value}) (根据条件删除数据)
  8. help (输出mongodb的帮助)
  9. db help() (数据库的帮助命令)

关于mongodb更多

node与mongodb交互

1
2
3
4
5
6
7
8
// 插入操作
function insertDocuments(db, data, callback) {
let collection = db.collection('documents');
collection.insertOne(data, (err, result) => {
assert.equal(err, null);
callback(result);
});
}
1
2
3
4
5
6
7
8
9
10
11
12
// 查找操作
function findDocuments(db, callback, search) {
search = search || {};

// Get the documents collection
let collection = db.collection('documents');
// Find some documents
collection.find(search).toArray((err, docs) => {
assert.equal(err, null);
callback(docs);
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 更新操作
function updateDocument(db, userinfo, money, callback) {

// Get the documents collection
let collection = db.collection('documents');

collection.updateOne({
idCard: userinfo
}, {
$set: {
money: money
}
}, (err, result) => {
assert.equal(err, null);
callback(result);
});
}
1
2
3
4
5
6
7
function deleteDocument(db, userinfo, callback) {
// Get the documents collection
let collection = db.collection('documents');
collection.deleteOne({ idCard: userinfo }, (err, result) => {
callback(result);
});
}

更多node与mongodb交互