Ejemplo n.º 1
0
    def test_collection(self):
        # Test that we can create a collection directly, not just from
        # MotorClient's accessors
        db = self.cx.pymongo_test
        collection = motor.MotorCollection(db, 'test_collection')

        # Make sure we got the right collection and it can do an operation
        doc = yield collection.find_one({'_id': 1})
        self.assertEqual(1, doc['_id'])
Ejemplo n.º 2
0
    def __init__(self, database, name, **kwargs):
        if not isinstance(database, Database):
            raise TypeError(
                "First argument to synchro Collection must be synchro "
                "Database, not %s" % repr(database))

        self.database = database
        self.delegate = kwargs.get('delegate') or motor.MotorCollection(
            self.database.delegate, name, **kwargs)

        if not isinstance(self.delegate, motor.MotorCollection):
            raise TypeError("Expected to get synchro Collection from Database,"
                            " got %s" % repr(self.delegate))
Ejemplo n.º 3
0
    async def test_collection(self):
        # Test that we can create a collection directly, not just from
        # MotorClient's accessors
        collection = motor.MotorCollection(self.db, "test_collection")

        # Make sure we got the right collection and it can do an operation
        self.assertEqual("test_collection", collection.name)
        await collection.insert_one({"_id": 1})
        doc = await collection.find_one({"_id": 1})
        self.assertEqual(1, doc["_id"])

        # If you pass kwargs to PyMongo's Collection(), it calls
        # db.create_collection(). Motor can't do I/O in a constructor
        # so this is prohibited.
        self.assertRaises(TypeError,
                          motor.MotorCollection,
                          self.db,
                          "test_collection",
                          capped=True)
Ejemplo n.º 4
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')