您的位置:首页 > 产品设计 > UI/UE

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: