本文整理汇总了TypeScript中mongoose.Types.ObjectId方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Types.ObjectId方法的具体用法?TypeScript Types.ObjectId怎么用?TypeScript Types.ObjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoose.Types
的用法示例。
在下文中一共展示了Types.ObjectId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
Account.statics.verifyAccount = function(verificationCode: string, cb) {
//console.log("inside verify account:" + verificationCode);
this.findOne({
'verificationCode': mongoose.Types.ObjectId(verificationCode)
},
'username',
(err, user) => {
if (user != null) {
//console.log("User with verificationCode: " + verificationCode);
if (err) {
//console.log("findUserByVerficationCode: " + err);
cb(err, null);
};
user.verificationCode = null;
user.isVerified = true;
user.save(function(saveErr) {
if (saveErr) {
return cb(saveErr);
}
cb(null, user);
});
}else{
cb({error: 'Invalid verification code or verification code no longer valid.'}, null);
}
});
}
示例2: DislikeComentario
export function DislikeComentario(req: express.Request, res: express.Response, next: NextFunction) {
Comentario.findOneAndUpdate({_id: mongoose.Types.ObjectId(req.params.id)}, {$inc : {"dislike" : 1}}).exec(function(err, comentario) {
if (err) return errorHandler.handleError(res, err);
res.json(comentario);
});
}
示例3: getOneTema
export function getOneTema(req: express.Request, res: express.Response, next: NextFunction) {
const tema_id = mongoose.Types.ObjectId(req.params.tema_id);
Tema.findOne({_id: tema_id}).exec(function (err, tema) {
if (err) return next();
res.json(tema);
});
}
示例4:
const results = await Promise.all(users.map(user => {
return Channel.update({
user_id: mongoose.Types.ObjectId(user._id.$oid),
type: CHANNEL_TYPE_MAIN
}, {profileImg: user.profileImg});
//
// return Channel.findOneAndUpdate(
// {
// user_id: mongoose.Types.ObjectId(user._id.$oid),
// type: CHANNEL_TYPE_MAIN
// }, {
// user_id: mongoose.Types.ObjectId(user._id.$oid),
// name: user.username,
// profileImg: user.profileImg
// },
// {
// upsert: true,
// new: true,
// setDefaultsOnInsert: true
// },
// (err, res) => {
// console.log('err', err);
// console.log('res', res);
// // Deal with the response data/error
// });
}));
示例5: function
const decline: TDeclineFunc = async function(this: IFriendshipDocument, declinedUserId) {
if (!this.accepted) {
if (!this.senderId.equals(declinedUserId)) {
throw new WrongUserDeclineFriendshipError();
}
await this.remove();
return null;
}
if (!this.senderId.equals(declinedUserId) && !this.receiverId.equals(declinedUserId)) {
throw new WrongUserDeclineFriendshipError();
}
if (this.receiverId.equals(declinedUserId)) {
this.accepted = false;
await this.save();
return this;
}
this.senderId = this.receiverId;
this.receiverId = mongoose.Types.ObjectId(declinedUserId);
this.accepted = false;
await this.save();
return this;
};
示例6: getCurrentPost
export function getCurrentPost(req: express.Request, res: express.Response, next: NextFunction) {
console.log("ID: " + req.params.postid);
Post.findOne({_id: mongoose.Types.ObjectId(req.params.postid)}).exec(function(error, post) {
if (error) {
return next(); }
res.json(post);
});
}
示例7: function
app.get('/booking', function (req, res) {
Booking.find({ userID: mongoose.Types.ObjectId("53b81a2f034eb5db75ec16ad")}, function (err, booking:any[]) {
if (err) return console.log(err);
res.send(booking);
});
console.log('get booking',req.body);
});
示例8: deletePost
export function deletePost(req: express.Request, res: express.Response, next: NextFunction ) {
Post.deleteOne({_id: mongoose.Types.ObjectId(req.params.postid) }).exec(function(error, post) {
if (error) return next();
return res.json(post);
});
}