Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

如何把这段mongoose缩减得更加优美?

$
0
0

听说有一个方法是如果已经有了相同的结果,则不更新.

	Friendlink.find(
		{
			linkname: new_linkname
		},
		null,
		{
			limit: 1
		}
		function(err,result){
			if(err) throw err;
			if(result.length){
				res.send('相同的链接名已经存在!');
			}else{
				Friendlink.update(
					{
						linkname: initial_linkname
					},
					{
						linkname: new_linkname, 
						linkurl: new_linkurl
					},
					{
						upsert: true
					},
					function(err){
						if(err) throw err;
						res.send('Success to Update!');
					}
				);
			}
		}
	);

Viewing all articles
Browse latest Browse all 14821

Trending Articles