示例#1
0
    def test_database(self):
        # Test that we can create a db directly, not just from MotorClient's
        # accessors
        db = motor.MotorDatabase(self.cx, 'pymongo_test')

        # Make sure we got the right DB and it can do an operation
        doc = yield db.test_collection.find_one({'_id': 1})
        self.assertEqual(hex(1), doc['s'])
示例#2
0
    async def test_database(self):
        # Test that we can create a db directly, not just from MotorClient's
        # accessors
        db = motor.MotorDatabase(self.cx, "motor_test")

        # Make sure we got the right DB and it can do an operation
        self.assertEqual("motor_test", db.name)
        await db.test_collection.insert_one({"_id": 1})
        doc = await db.test_collection.find_one({"_id": 1})
        self.assertEqual(1, doc["_id"])
示例#3
0
    def test_database(self):
        # Test that we can create a db directly, not just from MotorClient's
        # accessors
        db = motor.MotorDatabase(self.cx, 'motor_test')

        # Make sure we got the right DB and it can do an operation
        self.assertEqual('motor_test', db.name)
        test.sync_collection.insert({'_id': 1})
        doc = yield db.test_collection.find_one({'_id': 1})
        self.assertEqual(1, doc['_id'])
示例#4
0
    def __init__(self, client, name, **kwargs):
        assert isinstance(client, MongoClient), "Expected MongoClient, got %s" % repr(client)

        self._client = client
        self.delegate = kwargs.get("delegate") or motor.MotorDatabase(
            client.delegate, name, **kwargs
        )

        assert isinstance(
            self.delegate, motor.MotorDatabase
        ), "synchro.Database delegate must be MotorDatabase, not %s" % repr(self.delegate)
示例#5
0
            insert_item['_id'] = count
            count += 1
            yield insert_item

def shelve(result, error):
    if error:
        print('error getting user!', error)
    else:
        name = "%02d_%s" % (i, result['file'])
        d['name'].append(name)
        d['_id'].append(result['_id'])
        d['state'].append(result['state'])
        d['channel'].append(result['channel'])
        print("Just posted: " + name)


@gen.coroutine
def bulk_write():
    global d
    d = defaultdict(list)
    collection.insert((i for i in insert_patient('Dog_2')), callback=shelve)


if __name__ == "__main__":
    client = motor.MotorClient()
    db = motor.MotorDatabase(client, 'gingivere')
    collection = motor.MotorCollection(db, 'Dog_1')
    tornado.ioloop.IOLoop.current().run_sync(bulk_write)
    df = pd.DataFrame(d)
    shelve_api.insert(df, 'test_dog_1')