def test_aggregate(self): api.set_shard_at_rest('dummy', 1, "dest1/test_sharding") api.set_shard_at_rest('dummy', 2, "dest2/test_sharding") for y in range(10): doc1 = {'x': 1, 'y': y} doc2 = {'x': 2, 'y': y} self.db1.dummy.insert(doc1) self.db2.dummy.insert(doc2) pipeline = [ { '$match': { 'x': 2 } }, { '$group': { '_id': 'total', 's': { '$sum': '$y' } } }, ] result = operations.multishard_aggregate('dummy', pipeline)['result'] self.assertEquals([{'_id': 'total', 's': 45}], result)
def test_aggregate(self): for y in range(10): doc1 = {'x': 1, 'y': y} doc2 = {'x': 2, 'y': y} self.db1.dummy.insert(doc1) self.db2.dummy.insert(doc2) pipeline = [ {'$match': {'x': 2}}, {'$group': {'_id': 'total', 's': {'$sum': '$y'}}}, ] result = list(operations.multishard_aggregate('dummy', pipeline)) self.assertEquals([{'_id': 'total', 's': 45}], result)
def test_aggregate(self): api.set_shard_at_rest('dummy', 1, "dest1/test_sharding") api.set_shard_at_rest('dummy', 2, "dest2/test_sharding") for y in range(10): doc1 = {'x': 1, 'y': y} doc2 = {'x': 2, 'y': y} self.db1.dummy.insert(doc1) self.db2.dummy.insert(doc2) pipeline = [ {'$match': {'x': 2}}, {'$group': {'_id': 'total', 's': {'$sum': '$y'}}}, ] result = operations.multishard_aggregate('dummy', pipeline)['result'] self.assertEquals([{'_id': 'total', 's': 45}], result)
def aggregate(self, *args, **kwargs): return operations.multishard_aggregate(self.collection_name, with_options=self._with_options, *args, **kwargs)
def aggregate(self, *args, **kwargs): return operations.multishard_aggregate( self.collection_name, with_options=self._with_options, *args, **kwargs)