Mongoes:
We need a field, revision_id, to trivially increment, on the server,
each time we add a record.
We could do this using a counter table, per...
http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-SequenceNumbers
...or we could just select the maximum revision_id, each time we
write. Regardless which way we do it, the binding between pymongo and
JavaScript does not seem to be working. Here's my feeb attempt:
from pymongo import Connection
db = Connection().some_database
db.Fog.drop()
fog_table = db.Fog
db.system_js.counter = ''' function() {
var rets = db.Fog.find( { }, { _id:0,
revision_id:1} ).sort( { revision_id: 1 } ).limit(-1);
if (rets.length > 0 && rets[0].revision_id)
return rets[0].revision_id + 1;
return 10001;
} '''
for x in range(1, 100):
fog_table.insert( { 'revision_id': db.system_js.counter(),
'_value': 'Yar_%i' % x } )
for record in fog_table.find():
print record
That blurts out a table full of broken revision_ids:
{u'_value': u'Yar_32', u'revision_id': 10001.0, u'_id':
ObjectId('4e...')}
{u'_value': u'Yar_33', u'revision_id': 10001.0, u'_id':
ObjectId('4e...')}
{u'_value': u'Yar_34', u'revision_id': 10001.0, u'_id':
ObjectId('4e...')}
Note this is only useful to us if _js.counter() evaluates on the
server, because we hope to have many clients posting data.
So where are we going wrong?
--
Phlip
http://bit.ly/ZeekLand