Comments on: node.js and mongo (using mongoose) tutorial http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/ michael mukhin . los angeles . playing with javascript, node.js, php, socket.io, sand on sunny days Wed, 28 Jan 2015 04:50:26 +0000 hourly 1 http://wordpress.org/?v=4.1 By: Useful js | Pearltrees http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-12281 Wed, 14 Aug 2013 08:37:02 +0000 http://psitsmike.com/?p=107#comment-12281 […] node.js and mongo (using mongoose) tutorial – michael mukhin […]

]]>
By: Nodester Node.JS + Express + Mongo App Part 1 – Nodester | Java Development with MongoDB http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-6585 Fri, 29 Mar 2013 17:17:35 +0000 http://psitsmike.com/?p=107#comment-6585 […] Node.JS / Mongodb / Mongoose Tutorial […]

]]>
By: soyuka http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-3958 Thu, 31 Jan 2013 07:47:27 +0000 http://psitsmike.com/?p=107#comment-3958 You could use “unique : true” to make the username unique through mongoDB (http://mongoosejs.com/docs/api.html#schematype_SchemaType-unique) but be careful with it because it’s throwing an MongoDB error and not a ValidationError from mongoose.

The tip is to check the error by adding to your model :
Schema.on(‘save’, function(err, data) {
//check error there before saving
});

Thanks for the great tutorials and nice related docs about injection !

P.S. : for useless comments, please RTFM first…

]]>
By: michael mukhin http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-2698 Fri, 05 Oct 2012 05:54:14 +0000 http://psitsmike.com/?p=107#comment-2698 Push, pop, save I would imagine

]]>
By: Utuxia Consulting (@utuxia) http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-2681 Wed, 03 Oct 2012 08:23:41 +0000 http://psitsmike.com/?p=107#comment-2681 How would I add and delete hobbies from the person.hobbies object?

]]>
By: michael mukhin http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-1645 Thu, 26 Apr 2012 16:34:00 +0000 http://psitsmike.com/?p=107#comment-1645 Please ask on stackoverflow.com :)

]]>
By: jack http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-1643 Thu, 26 Apr 2012 13:27:51 +0000 http://psitsmike.com/?p=107#comment-1643 Hi michael mukhin

i want return value from asynchronous function .here I want to store query result into variable.

var listcounter;

// define our function with the callback argument

function personCount(room,callback) {

listperson.listactivecount(room,’Active’,function(error, gameactivecount){callback( error,gameactivecount);});

}

personCount(room, function(error,num) {
// this anonymous function will run when the
// callback is called
listcounter=num;
console.log(“callback called! ” + num);
});

console.log(listcounter);//here i want to display listpersoncount.How can i return listpersoncount .

plz help me

]]>
By: michael mukhin http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-1635 Wed, 25 Apr 2012 16:35:08 +0000 http://psitsmike.com/?p=107#comment-1635 You need to have a function w/ a callback. Person.count is asynchronous, so the code “console.log” may (will) get executed before the return and the return is in a different scope. So you can do this:

function personCount(callback) {
Person.count(room, function(error, count){ callback(error, count); });
}

The “callback” is a “a reference to a piece of executable code, that is passed as an argument to other code.” This might help – http://recurial.com/programming/understanding-callback-functions-in-javascript/

]]>
By: jack http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-1632 Wed, 25 Apr 2012 11:17:56 +0000 http://psitsmike.com/?p=107#comment-1632 how to store query result into variable?

like below query
var first;
Person.count(room, function(error, count){
return first;
});
console.log(first);

]]>
By: michael mukhin http://psitsmike.com/2012/02/node-js-and-mongo-using-mongoose-tutorial/#comment-1183 Tue, 06 Mar 2012 06:54:19 +0000 http://psitsmike.com/?p=107#comment-1183 Sure thing, hopefully it made sense and helped.

]]>