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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

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交互