您的位置:首页 > 数据库 > Mongodb

mongodb query promise sample

2014-01-16 11:01 176 查看

http://mongoosejs.com/docs/api.html#promise_Promise


Promise#then(
onFulFill
onReject
)

Creates a new promise and returns it. If 
onFulfill
 or 
onReject
 are passed,
they are added as SUCCESS/ERROR callbacks to this promise after the nextTick.

Parameters:

onFulFill
 <Function>
onReject
 <Function>

Returns:

<Promise> newPromise

See:

promises-A+
mpromise#then

Conforms to promises/A+ specification.

Example:

var promise = Meetups.find({ tags: 'javascript' }).select('_id').exec();
promise.then(function (meetups) {
var ids = meetups.map(function (m) {
return m._id;
});
return People.find({ meetups: { $in: ids }).exec();
}).then(function (people) {
if (people.length < 10000) {
throw new Error('Too few people!!!');
} else {
throw new Error('Still need more people!!!');
}
}).then(null, function (err) {
assert.ok(err instanceof Error);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: