Example #1
0
def load_to_mongo(documents: List[dict]) -> None:
    client = MongoClient(config('MONGO_URI'))
    db = client.momenteur
    collection = db.timestamped_comments

    for doc in documents:
        doc['_id'] = str(uuid.uuid1())
        doc['created_at'] = datetime.now()
        collection.insert(doc)
def set_meeting_booking():
    collection.insert({
        'roomName': param["location"],
        'booked': {
            'date': param["meetingDate"],
            'startTime': param["startTime"],
            'endTime': param["endTime"]
        }
    })
    return
Example #3
0
	def add_note(self, collection, uid, password):
		"""adds a note with default title to a collection"""
		if uid == 0:
			uid = uuid.uuid4()
		notesapp.GUI.notecount = collection.count()+1
		title = notesapp.GUI.initial_notetitle.fget('initial_notetitle') + (
			repr(notesapp.GUI.notecount) )
		if password:
                        encry_title = encryption.encrypt_text(title, password)
                        collection.insert({'_id': str(uid),'title': encry_title, 'body': '', 
			'created_at': datetime.now().isoformat(' ')})
                else:
                        collection.insert({'_id': str(uid),'title': title, 'body': '',
                                'created_at': datetime.now().isoformat(' ')})
		return (title, uid) # used in get_title 
Example #4
0
def update(collection, query, object):
    existing = collection.find_one(query)
    col_name = collection.full_name
    obj_id = "FAIL"
    if existing:
        if existing.keys() == object.keys():
            obj_id = existing["_id"]
            log("%s: Not updated: " % col_name, obj_id)
        else:
            obj_id = collection.insert(object)
            log("%s: Updated object: " % col_name, obj_id)
    else:
        obj_id = collection.insert(object)
        log("%s: Inserted object: " % col_name, obj_id)

    return obj_id
Example #5
0
def testAddMongDB():
    try:
        token = crypto.get_random_string()
        enpass = crypto.PasswordCrypto.get_encrypted("fanfan120725")

        now = datetime.datetime.utcnow()

        collection.insert({
            "name": "songck",
            "passwd": enpass,
            "email": "*****@*****.**",
            "token": token,
            "token_time": now
        })
    except Exception, e:
        print '**********', e
Example #6
0
def insert_poly(collection):
    """
    Shuffle polygon data from GeoJSON to DB Document and insert into DB 
    """
    # load geojson file
    with open("../data/landesgrenze_WGS84.geojson") as f:
        data = json.load(f)
    
    # geojson to mongo doc
    for feature in data["features"]:
        feature_dict = {}
        feature_dict["name"] = "state_boundary"
        feature_dict["loc"] = feature["geometry"]
        
        # insert in db collection        
        collection.insert(feature_dict)
Example #7
0
def insert_point(collection):
    """
    Shuffle point data from GeoJSON to DB Document and insert into DB 
    """
    # load geojson file
    with open("../data/febs_wiki.geojson") as f:
        data = json.load(f)
    
    # geojson to mongo doc
    for feature in data["features"]:
        feature_dict = {}
        feature_dict["name"] = feature["properties"]["name"]
        feature_dict["type"] = feature["properties"]["type"]
        feature_dict["url"] = feature["properties"]["url"]
        location = {}
        feature_type = feature["geometry"]["type"]
        location["type"] = feature_type
        location["coordinates"] = feature["geometry"]["coordinates"] 
        feature_dict["loc"] = location
        
        # insert in db collection        
        collection.insert(feature_dict)
Example #8
0
    def update(self, ii, data_to_send):

        # Access collection corresponding to the current time-step:
        collection_name = '%s' % ii
        try:
            collection = self.db.create_collection(
                collection_name, **{
                    'capped': True,
                    'size': 100000
                })
        except (pymongo.errors.OperationFailure,
                pymongo.errors.CollectionInvalid):
            collection = self.db[collection_name]

        # Push my data:
        collection.insert({
            "rank": self.rank(),
            'data': json.dumps(data_to_send)
        })

        #Get data:
        max_record = len(self.outside_rank_list)
        cursor = collection.find({'rank': {
            "$in": self.outside_rank_list
        }},
                                 cursor_type=CursorType.TAILABLE_AWAIT)
        result_dict = {}
        while len(result_dict) < max_record:
            try:
                found_document = cursor.next()
                result_dict[found_document['rank']] = found_document['data']
            except StopIteration:
                pass

        for source_rank, payload in result_dict.items():
            self.received_message_dict_external[source_rank][ii] = json.loads(
                payload)
Example #9
0
def insert(collection, object):
    obj_id = collection.insert(object)  # Hmhmho. How useful.
    log("%s: Inserted object: " % collection.full_name, obj_id)
    return obj_id
Example #10
0
#!/usr/bin/python
# coding:utf-8
'''

'''
import pymongo
import pymongo.collection

# 创建一个mongo客户端
client = pymongo.MongoClient("127.0.0.1", 27017)

#获得mongoDB中的数据库对象
db = client.runoob

#在数据库中创建一个集合
collection = db.runoob

jike = {'_id': '324', 'name ': '刘生tg ', "age": 5, "skill": "python"}

god = {"_id": 34, "name": "张三", "teacher": "unknow"}

#插入数据
collection.insert(jike)
collection.insert(god)

print collection