It looks like you copied/pasted some code from that example page, but
the javascript in that example is for the mongo shell, not the NodeJS
driver, which is why hasNext() doesn't work here. You will need to
modify it so that it uses the callback function semantics.
In the node driver, .find() returns a cursor which you must then use
with .toArray(), .each() or .nextObject() to step through each
document.
> I will use the auto increment field for *serial number(sno)* in my below
> coding.
>
> var insertData = function(err, collection){
> while( 1 ) {
> *var c =
> collection.find({},{sno:1}).sort({sno:-1}).limit(1);
> var i = hasNext() ? c.next().sno + 1 : 1;*
>
> collection.save({"Phonenumber":ph_value.phonenumber,"Keyword":ph_value.keyw ord,"sno":i,"Date":dateFormat(new
> Date(), "dd-mm-yyyy HH:MM:ss")});
> break;
> }
> }
>
> *It will give the error.*
>
> C:\Program Files\nodejs>node sample.js
> Server running athttp://
127.0.0.1:8000/
>
> C:\Program Files\nodejs\sample.js:23
> var i = hasNext() ?
> c.next().sno
> + 1 : 1;
> ^
> *ReferenceError: hasNext is not defined*
> at C:\Program Files\nodejs\sample.js:23:22
> at Db.collection (C:\Program
> Files\nodejs\node_modules\mongodb\lib\mongodb\d
> b.js:447:44)
> at C:\Program Files\nodejs\sample.js:30:18
> at C:\Program Files\nodejs\node_modules\mongodb\lib\mongodb\db.js:247:16
> at [object Object].<anonymous> (C:\Program
> Files\nodejs\node_modules\mongodb
> \lib\mongodb\connection\server.js:383:7)
> at [object Object].emit (events.js:88:20)
> at [object Object].<anonymous> (C:\Program
> Files\nodejs\node_modules\mongodb
> \lib\mongodb\connection\connection_pool.js:93:15)
> at [object Object].emit (events.js:70:17)
> at Socket.<anonymous> (C:\Program
> Files\nodejs\node_modules\mongodb\lib\mong
> odb\connection\connection.js:385:10)
> at Socket.emit (events.js:67:17)
>
> Thanks in advance.
> Sankaravelu.S
>
>
>
>
>
>
>
> On Thu, Jun 14, 2012 at 12:45 PM, Sam Millman <
sam.mill...@gmail.com> wrote:
> > This should give you the theory of how to do what you want:
> >
http://www.mongodb.org/display/DOCS/How+to+Make+an+Auto+Incrementing+...
>
> > On 14 June 2012 04:59, Sankaravelu S <
san...@hexolabs.com> wrote:
>
> >> Hi,
>
> >> I am using mongodb 2.0.6 and nodejs 0.6.19.
>
> >> Below program,
>
> >> I had one html page for user to enter the phone_number and keyword.
>
> >> In this keyword and Phone_number is stored into Replica set through
> >> the mongos server 27021.
>
> >> Now i want to create *auto increment field for serial number*(sno).
> >> *"**sno":1*, "Date":dateFormat(new Date(), "dd-mm-yyyy HH:MM:ss")});
> >> break;
> >> }
> >> }
>
> >> client.open(function(err, pClient){
> >> client.collection('demo', insertData);
>
> >> });
>
> >> });
> >> }
> >> res.end();
> >> }).listen(8000, '127.0.0.1');
> >> console.log('Server running athttp://
127.0.0.1:8000/');