mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Simplify code.
Pop the `_id` when receiving the document on the changefeed
This commit is contained in:
parent
0d11c3a7a8
commit
ea4d01dec0
@ -34,11 +34,6 @@ class MongoDBChangeFeed(ChangeFeed):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def run_changefeed(self):
|
def run_changefeed(self):
|
||||||
# this is kinda a hack to make sure that the connection object is
|
|
||||||
# setup
|
|
||||||
self.connection._connect()
|
|
||||||
# namespace to allow us to only listen to changes in a single
|
|
||||||
# collection
|
|
||||||
dbname = self.connection.dbname
|
dbname = self.connection.dbname
|
||||||
table = self.table
|
table = self.table
|
||||||
namespace = '{}.{}'.format(dbname, table)
|
namespace = '{}.{}'.format(dbname, table)
|
||||||
@ -61,23 +56,28 @@ class MongoDBChangeFeed(ChangeFeed):
|
|||||||
record = cursor.next()
|
record = cursor.next()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
is_insert = record['op'] == 'i'
|
is_insert = record['op'] == 'i'
|
||||||
is_delete = record['op'] == 'd'
|
is_delete = record['op'] == 'd'
|
||||||
is_update = record['op'] == 'u'
|
is_update = record['op'] == 'u'
|
||||||
|
|
||||||
|
# mongodb documents uses the `_id` for the primary key.
|
||||||
|
# We are not using this field at this point and we need to
|
||||||
|
# remove it to prevent problems with schema validation.
|
||||||
|
# See https://github.com/bigchaindb/bigchaindb/issues/992
|
||||||
if is_insert and (self.operation & ChangeFeed.INSERT):
|
if is_insert and (self.operation & ChangeFeed.INSERT):
|
||||||
self.outqueue.put(record['o'])
|
record['o'].pop('_id', None)
|
||||||
|
doc = record['o']
|
||||||
elif is_delete and (self.operation & ChangeFeed.DELETE):
|
elif is_delete and (self.operation & ChangeFeed.DELETE):
|
||||||
# on delete it only returns the id of the document
|
# on delete it only returns the id of the document
|
||||||
self.outqueue.put(record['o'])
|
doc = record['o']
|
||||||
elif is_update and (self.operation & ChangeFeed.UPDATE):
|
elif is_update and (self.operation & ChangeFeed.UPDATE):
|
||||||
# the oplog entry for updates only returns the update
|
# the oplog entry for updates only returns the update
|
||||||
# operations to apply to the document and not the
|
# operations to apply to the document and not the
|
||||||
# document itself. So here we first read the document
|
# document itself. So here we first read the document
|
||||||
# and then return it
|
# and then return it.
|
||||||
doc = self.connection.conn[dbname][table]\
|
doc = self.connection.conn[dbname][table]\
|
||||||
.find_one(record['o2'])
|
.find_one(record['o2'], projection={'_id': False})
|
||||||
self.outqueue.put(doc)
|
self.outqueue.put(doc)
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,8 +44,6 @@ class BlockPipeline:
|
|||||||
if tx['assignee'] == self.bigchain.me:
|
if tx['assignee'] == self.bigchain.me:
|
||||||
tx.pop('assignee')
|
tx.pop('assignee')
|
||||||
tx.pop('assignment_timestamp')
|
tx.pop('assignment_timestamp')
|
||||||
# required for mongodb
|
|
||||||
tx.pop('_id', None)
|
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def validate_tx(self, tx):
|
def validate_tx(self, tx):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user