Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.
/ scenic Public archive

Commit

Permalink
Use 'findOne' instead of 'find' for mongoose models.
Browse files Browse the repository at this point in the history
Replace 'find' with 'findOne' for refactoring issue.
  • Loading branch information
Hyeonje Alex Jun committed Nov 13, 2012
1 parent b1ef429 commit 56d5867
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions server/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ function Handlers(web) {

this.channel = {
get: function(req, res) {
ChannelModel.find({name: req.params.name}, function(err, docs) {
var channel = null;
if(docs.length) {
channel = docs[0];
}
else {
ChannelModel.findOne({name: req.params.name}, function(err, channel) {
if (channel === null) {
// create new channel
channel = new ChannelModel({name: req.params.name, pictures: []});
channel.save();
Expand Down
8 changes: 2 additions & 6 deletions server/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ function Socket(web) {
user.join(channels[data.channel]);
}
else {
ChannelModel.find({name: data.channel}, function(err, channel_results) {
var channel = null;
if(channel_results.length) {
channel = channel_results[0];
}
else {
ChannelModel.findOne({name: data.channel}, function(err, channel) {
if(channel === null) {
// create new
channel = new ChannelModel({name: data.channel, pictures: []});
channel.save();
Expand Down

0 comments on commit 56d5867

Please sign in to comment.