expreiment to see what a callback function should be When executing a query
2017-02-14 18:33
423 查看
run the following step:
npm init
npm install mongolass -save
new a file app.js
add the following content according to file 'README.md' in mongolass module
const Mongolass = require('mongolass');
const mongolass = new Mongolass();
mongolass.connect('mongodb://localhost:27017/test');
const User = mongolass.model('User', {
name: { type: 'string' },
age: { type: 'number' }
});
User
.insertOne({ name: 'nswbmw', age: 12 })
.exec()
.then(
console.log
)
.catch(function (e) {
console.error(e);
console.error(e.stack);
});
let us see the what the mongodb return
so let us see some code
// 通过用户 id 和文章 id 删除一篇文章
delPostById: function delPostById(postId, author) {
return Post.remove({ author: author, _id: postId })
.exec()
.then(function (res) {
// 文章删除后,再删除该文章下的所有留言
if (res.result.ok && res.result.n > 0) {
return CommentModel.delCommentsByPostId(postId);
}
});
}
why that is the statement "if (res.result.ok && res.result.n > 0) {"
it is for some reason
npm init
npm install mongolass -save
new a file app.js
add the following content according to file 'README.md' in mongolass module
const Mongolass = require('mongolass');
const mongolass = new Mongolass();
mongolass.connect('mongodb://localhost:27017/test');
const User = mongolass.model('User', {
name: { type: 'string' },
age: { type: 'number' }
});
User
.insertOne({ name: 'nswbmw', age: 12 })
.exec()
.then(
console.log
)
.catch(function (e) {
console.error(e);
console.error(e.stack);
});
let us see the what the mongodb return
so let us see some code
// 通过用户 id 和文章 id 删除一篇文章
delPostById: function delPostById(postId, author) {
return Post.remove({ author: author, _id: postId })
.exec()
.then(function (res) {
// 文章删除后,再删除该文章下的所有留言
if (res.result.ok && res.result.n > 0) {
return CommentModel.delCommentsByPostId(postId);
}
});
}
why that is the statement "if (res.result.ok && res.result.n > 0) {"
it is for some reason
相关文章推荐
- 第一次使用echart从后台获取数据动态显示到页面
- 使用Vue.js过程中,踩过的坑
- leetcode 95. Unique Binary Search Trees II
- Burpsuit提示Handshake_failure的解决办法
- UITextView光标在中间的问题
- BZOJ 4393 Fruit Feast
- mybatis中Invalid bound statement (not found) 和 Result Maps collection already contains value for...错误解决方案
- @Responsebody与@RequestBody
- UE4 BehaviorTree笔记
- 从饭店谈起,看支付宝Zqueue系统如何应对双11
- JAVA中String、StringBuffer、StringBuilder的区别
- scala 中的def/val/lazy val/的区别,call-by-value/call-by-name
- Duilib程序中弹出文件对话框
- druid数据源及监控界面配置
- arduino交替采集两个脉冲信号
- arduino采集温湿度
- Caffe: Data layer prefetch queue empty
- string、stringbuffer和stringbuilder的区别
- php 引入文件 include 和require
- Druid初学习