用户架构:
var UserSchema = new Schema({
name: { type: String, required:true },
email: { type: String, required:true, lowercase: true , index : { unique: true } },
password : { type: String, required:true , select:true },
blog_bookmarks: [{ type: String }]
});
Run Code Online (Sandbox Code Playgroud)
blog_bookmarks用于为特定用户添加值的API
api.post('/add_bookmark_blog', function(req, res){
User.findOne({_id: req.query.user_id}, function(err, user){
if(err)
{
res.json(err)
}
else{
var blogid = req.body.blog_id;
user.find({ blog_bookmarks : blogid}, function(res1, result){
if(res1){
user.blog_bookmarks.push(blogid);
user.save(function(err) {
if(err){
res.json('ERROR at adding bookmark')
}
else {
res.json('bookmark for …Run Code Online (Sandbox Code Playgroud)