Is there any way of implementing a counters collection as described in the docs with node-mongodb-native?
I'm trying to avoid doing this by nesting over 9000 callbacks (which IMHO sounds untidy and not-elegant) but the good people who wrote this native driver refused to implement synchronous/blocking calls.
Does the native driver provide a someway to call user defined functions and use their return values during queries? Or could there be an alternate way of extracting a sequential count....maybe solely from an ObjectID()
?
Any ideas?
EDIT:
This is not for the _id
field (That's taken care of by db.coll.save(x)
)
I have different types of documents in a collection. Each of these needs its own "type serial" or "type sequence" if you know what i mean.
I've already implemented this (plus other stuff) with afew nested calls as shown bellow. doc
is JSON.parse
'd from the client. I have to return this doc
to the client with an _id
(sorted by db.coll.save
) and with a typeserial
(currently being sorted by db.coll.count
as shown bellow)
///more nesting Async calls above.
db.collection('dox').count( { "type" : doc.type } ,
function( err , count )
{
///{some err checking code here}
doc.typeseq = (1+count);
db.collection('dox').save( doc ,
function( err , doc )
{
///{more code here}
///Finally return JSON.stringified doc with new info/members to client-side
}
);
}
);
I'd just like to know if there is a more elegant, anti-async way of getting my doc.typeserial