def test_bool(self): with self.assertRaises(NotImplementedError): bool(Database(self.client, "test"))
def test_list_collections(self): self.client.drop_database("pymongo_test") db = Database(self.client, "pymongo_test") db.test.insert_one({"dummy": "object"}) db.test.mike.insert_one({"dummy": "object"}) results = db.list_collections() colls = [result["name"] for result in results] # All the collections present. self.assertTrue("test" in colls) self.assertTrue("test.mike" in colls) # No collection containing a '$'. for coll in colls: self.assertTrue("$" not in coll) # Duplicate check. coll_cnt = {} for coll in colls: try: # Found duplicate. coll_cnt[coll] += 1 self.assertTrue(False) except KeyError: coll_cnt[coll] = 1 coll_cnt = {} # Checking if is there any collection which don't exists. if (len(set(colls) - set(["test", "test.mike"])) == 0 or len(set(colls) - set(["test", "test.mike", "system.indexes"])) == 0): self.assertTrue(True) else: self.assertTrue(False) colls = db.list_collections(filter={"name": {"$regex": "^test$"}}) self.assertEqual(1, len(list(colls))) colls = db.list_collections(filter={"name": {"$regex": "^test.mike$"}}) self.assertEqual(1, len(list(colls))) db.drop_collection("test") db.create_collection("test", capped=True, size=4096) results = db.list_collections(filter={'options.capped': True}) colls = [result["name"] for result in results] # Checking only capped collections are present self.assertTrue("test" in colls) self.assertFalse("test.mike" in colls) # No collection containing a '$'. for coll in colls: self.assertTrue("$" not in coll) # Duplicate check. coll_cnt = {} for coll in colls: try: # Found duplicate. coll_cnt[coll] += 1 self.assertTrue(False) except KeyError: coll_cnt[coll] = 1 coll_cnt = {} # Checking if is there any collection which don't exists. if (len(set(colls) - set(["test"])) == 0 or len(set(colls) - set(["test", "system.indexes"])) == 0): self.assertTrue(True) else: self.assertTrue(False) self.client.drop_database("pymongo_test")
def test_get_coll(self): db = Database(self.client, "pymongo_test") self.assertEqual(db.test, db["test"]) self.assertEqual(db.test, Collection(db, "test")) self.assertNotEqual(db.test, Collection(db, "mike")) self.assertEqual(db.test.mike, db["test.mike"])
def setUp(self): self.db = Database(get_connection(), "pymongo_test")
def test_get_default_database_with_authsource(self): # Ensure we distinguish database name from authSource. uri = "mongodb://%s:%d/foo?authSource=src" % (host, port) c = MongoClient(uri, _connect=False) self.assertEqual(Database(c, 'foo'), c.get_default_database())
Asistente conversacional Aragón Open Data_v1.0.0 Copyright © 2020 Gobierno de Aragón (España) Author: Instituto Tecnológico de Aragón ([email protected]) All rights reserved ''' from pymongo import MongoClient from pymongo.database import Database # Parameters for MongoDB connection URL = "mongodb" PORT = 27017 DB_NAME = "rasa" # Initialization of client and database client = MongoClient(host=URL, port=PORT) db = Database(client, DB_NAME) # Projects and models collections PROJECTS_COLL = db["projects"] MODELS_COLL = db["models"] # Intents and templates collections INTENTS_COLL = db["intents"] TEMPLATES_COLL = db["templates"] # Entities and values collections ENTITIES_COLL = db["entities"] VALUES_COLL = db["values"] # Stories collections STORIES_COLL = db["stories"]
def gather_profiler_data(mongod_client, database, start, end): query = {'ts': {'$gte': start, '$lte': end}} db = Database(mongod_client, database) return list(db.system.profile.find(query))
def test_process_collection(self): for setting in settings.PROCESS_CHECKS: collection = Collection( Database(Connection(u'127.0.0.1', 27017), u'amon_test'), u'amon_{0}'.format(setting)) eq_(backend.get_collection(setting), collection)
from pymongo import MongoClient from pymongo.database import Database from pymongo.collection import Collection shop_collection = Collection(Database(MongoClient(host='10.1.17.15'), 'dspider2'), 'shops') for i in shop_collection.find({'data_source':'餐饮', 'data_region':'千岛湖', 'data_website':'大众点评', 'shop_url':'http://www.dianping.com/shop/66205575'}): print(i.get('shop_time'))
def test_has_a_collection(self): self.assertEqual( Collection( Database(MongoClient('localhost', 27017), 'test_database'), 'samples'), self.Sample.collection)
from pprint import pprint from bson import ObjectId from pymongo import MongoClient from pymongo.database import Database from mongo_connector.projects import read_model_id_from_name, read_project_id_from_name from trainer import load_smalltalk_domain here = os.path.dirname(__file__) parent = os.path.dirname(here) SMALLTALK_DIR = os.path.join(parent, "data", "smalltalk") client = MongoClient("mongodb://mongodb:27017") db = Database(client, "rasa") def smalltalk_domain(): domain = load_smalltalk_domain() domain = domain.as_dict() return domain def insert_smalltak_stories(): domain = smalltalk_domain() data = {} with open(os.path.join(SMALLTALK_DIR, "stories.md")) as md: content = md.readlines() content = [x.replace("\n", "") for x in content] content = filter(lambda x: x.strip() != "", content)
def test_database_instance(self): self.assertEqual( isinstance(self.database.database, type(Database(self.client, self.db))), True)
from pymongo.mongo_client import MongoClient from pymongo.collection import Collection, ObjectId from pymongo.database import Database try: tasks_collection_name = 'tasks' defect_collection_name = 'defect' hsegap_collection_name = 'HSE_gaps_pbe_structure' db_info = { "aliases": {}, "database": "results_GY", "host": "marilyn.pcpm.ucl.ac.be", "port": 27017, "admin_user": "******", "admin_password": "******", "readonly_user": "******", "readonly_password": "******" } clt = MongoClient(host=db_info['host'], port=db_info['port']) db = Database(clt, db_info['database']) db.authenticate(db_info['admin_user'], db_info['admin_password']) except: print 'Can not connect database'
def setup_users(self): Database(self.database, 'admin').create_collection('users')
def test_cmp(self): self.assertNotEqual(Database(self.connection, "test"), Database(self.connection, "mike")) self.assertEqual(Database(self.connection, "test"), Database(self.connection, "test"))
#!/usr/loca/bin/python from pymongo.connection import Connection from pymongo.database import Database from pymongo.collection import Collection import FreebaseApi import AlchemyApiCategory import nerd # constants and globals MONGO_CON = '107.22.242.25:27017' mongo_con = Connection(MONGO_CON) MONGO_DB = 'queries' mongo_db = Database(mongo_con, MONGO_DB) MONGO_COL = 'hott_rends' mongo_col = Collection(mongo_db, MONGO_COL) # for specific data LOG_FILE = '/home/penser/tmp/specifics.txt' # for simple data STAT_PAPER = '/home/penser/tmp/stats.txt' # number of queries LIMIT = 400 # threshold to cut off unusual types THRESHOLD = 2 class HotTrendsAnalysisAl: ''' docs ''' def __init__(self): self.freebaseApi = FreebaseApi.FreebaseApi()
def test_repr(self): self.assertEqual(repr(Database(self.connection, "pymongo_test")), "Database(%r, u'pymongo_test')" % self.connection)
def test_name(self): self.assertRaises(TypeError, Database, self.client, 4) self.assertRaises(InvalidName, Database, self.client, "my db") self.assertRaises(InvalidName, Database, self.client, "my\x00db") self.assertRaises(InvalidName, Database, self.client, u("my\u0000db")) self.assertEqual("name", Database(self.client, "name").name)
def __init__(self): self.conn = MongoClient(host='127.0.0.1', port=27017) #self.db = self.conn.WorkLogDB self.db = Database(self.conn, "WorkLogDB")
del places['country'] # country del places['country abbreviation'] # country abbrev. information content = json.dumps( { 'country': country_name, # Return unique fields 'country abbreviation': country_abbv, 'post code': post_code, 'places': result }, # Return a list of possible places default=json_util.default) # Using pymongo json settings return (isFound, content) # Return True and JSON results # PRESENT GLOBAL ZIP = 'zip' NEARBY = 'nearby' with open(os.path.expanduser('~/environment.json')) as f: env = json.load(f) # Extract environment variables connection = Connection( env['DOTCLOUD_DB_MONGODB_URL']) # Connect to be w/ env info #connection = Connection() db = Database(connection, 'zip') # Get handle to ZIP db application = default_app() # WSGI application #run (host='localhost', port=8080) # Local Testing
def get_db(self): return Database(self.get_conn(), self.db)
def setUp(self): self.db = Database(get_client(), "pymongo_test")
def test_get_default_database(self): c = MongoClient("mongodb://%s:%d/foo" % (host, port), _connect=False) self.assertEqual(Database(c, 'foo'), c.get_default_database())
def test_repr(self): self.assertEqual( repr(Database(self.connection, "pymongo_test")), "Database(%r, %s)" % (self.connection, repr(u"pymongo_test")))
def test_hashable(self): self.assertIn(self.client.test, {Database(self.client, "test")})
def setUp(self): self.client = get_client() self.db = Database(self.client, "pymongo_test")
def test_repr(self): self.assertEqual(repr(Database(self.client, "pymongo_test")), "Database(%r, %s)" % (self.client, repr(u"pymongo_test")))
def test_name(self): self.assertRaises(TypeError, Database, self.connection, 4) self.assertRaises(InvalidName, Database, self.connection, "my db") self.assertEqual("name", Database(self.connection, "name").name())
def test_system_colllection(self): for setting in settings.SYSTEM_CHECKS: collection = Collection( Database(Connection(u'127.0.0.1', 27017), u'amon_test'), u'amon_{0}'.format(setting)) eq_(backend.get_collection(setting), collection)
def setUp(self): db = Database(get_connection(), "pymongo_test") TestDoc.objects.db = db TestDoc.objects.remove()