pymongo

Pymongo-text search-list of phrases

∥☆過路亽.° 提交于 2019-12-12 00:28:55
问题 I have a dictionary of the following structure: keywords={topic_1:{category_1:['\"phrase_1\"','\"phrase_2\"'], catgeory_2:[''\"phrase_1\"','\"phrase_2\"']}, topic_2:{category_1:['\"phrase_1\"','\"phrase_2\"','\"phrase_3\"']}} I have a bunch of documents in mongodb on which I want tag a [category,topic] tag as long as it matches any one of the phrases in the [topic][category].However I need to iterate phrase by phrase as follows( Pymongo) : for topic in keywords: for category in keywords[topic

MongoDB - Print

ぐ巨炮叔叔 提交于 2019-12-12 00:17:02
问题 I am interested in printing a range of query. I have the following code. start = datetime.datetime(2012, 2, 2, 6, 35, 6, 764) end = datetime.datetime(2012, 2, 2, 6, 55, 3, 381) for doc in db.model.find({'time': {'$gte': start, '$lt': end}}): print doc It does the job, printing out basically how I inserted the data. My question is this: Is it possible to print out one element of the whole query? Such as, I want it to only print the item or the date or another input inserted, not give me {'time

how to update sequence number in mongodb safely

。_饼干妹妹 提交于 2019-12-11 23:46:27
问题 In my mongodb database, there is a 'messages' collection, it has a field 'order' which values integer msg1.order=1, msg2.order=2, msg3.order=3, msg4.order=4, msg5.order=5, ... for each message, represents an ordered sequence of a sub-collection of messages. while, these messages can be re-sorted, via web page, using jquery.sortable. for example, If I move message on position No.3 to No.1, then I should change 'order' values to msg1.order=2, msg2.order=3, msg3.order=1, msg4.order=4, msg5.order

UnicodeDecodeError while iterating over MongoDB collection

给你一囗甜甜゛ 提交于 2019-12-11 20:22:23
问题 I am trying to query a MongoDB database using Python 2.7 and pymongo-2.3 using something like this: from pymongo import Connection connection = Connection() db = connection['db-name'] collections = db.subName entries = collections['collection-name'] print entries # > Collection(Database(Connection('localhost', 27017), u'db-name'), u'subName.collection-name') for entry in entries.find(): pass The iterator fails even though I don't do anything with the entry objects: Traceback (most recent call

PyMongo’s bulk write operation features with multiprocessing and generators

。_饼干妹妹 提交于 2019-12-11 19:57:01
问题 PyMongo supports generators for batch processing with sDB.insert(iter_something(converted)) . Bulk write operation features which executes write operations in batches in order to reduces the number of network round trips and increases write throughput. The following code seems to work, but I do not whether PyMongo still is able iterate the generator together with multiprocessing until it has yielded 1000 a documents or 16MB of data, then pause the generator while it inserts the batch into

Can you specify a key for $addToSet in Mongo?

社会主义新天地 提交于 2019-12-11 19:15:30
问题 I have a document: { 'profile_set' : [ { 'name' : 'nick', 'options' : 0 }, { 'name' : 'joe', 'options' : 2 }, { 'name' : 'burt', 'options' : 1 } ] } and would like to add a new document to the profile_set set if the name doesn't already exist (regardless of the option). So in this example if I tried to add: {'name' : 'matt', 'options' : 0} it should add it, but adding {'name' : 'nick', 'options' : 2} should do nothing because a document already exists with name nick even though the option is

Query to a List of dictionaries, return the specific dictionary?

空扰寡人 提交于 2019-12-11 17:39:38
问题 I pushed a db as simple as, using python, pymongo and mnogodb, the db is mae of many files like the sample below: def pushdata(): for filename in os.listdir(directory): with open( directory + filename , 'r') as f: datastore = json.load(f) m = data.insert_one(datastore) My jsons loook like that { "info": { "S1": { "SS": "1221" }, "S2": { "SDS011": "5121" }, "OP": "157.138", "LK": "32121", "MN": "122.077" }, "readings": [ { "SS1": "7.80", "SS2": "1.80", "timestamp": "1530857160" }, { "SS1": "9

How to implement Mongodb connection pooling in lambda function using pymongo

删除回忆录丶 提交于 2019-12-11 17:22:48
问题 I am using aws lambda function, python and monogdb atlas. I have executed the below code. client = MongoClient('mongodb+srv://app_user:123456@accesdev-dxjpa.mongodb.net/test') db = client.test def lambda_handler(event, context): print("Received event: " + json.dumps(event, indent=1)) user_profile = db.user_profile Email = event['email'] res = Email.find('@') if res == -1: disuname = list(user_profile.find({"username" : Email},{"name": 1, "photo": 1, "bio": 1})) uid = json.dumps(disuname,

how to store & update matching values based on $OR operator, in mongodb?

走远了吗. 提交于 2019-12-11 17:18:36
问题 My collections contain nested document and I'm trying to get "Text" present in any of the nested fields such as: var rerun = { $or: [ {"code_exception.java_40.code.Text": { $exists : true, $ne : "" } },//13816 {"code_exception.java_15.code.Text":{ $exists : true, $ne : ""} },//13485 {"code_exception.java_10.code.Text":{ $exists : true, $ne : ""} },//12994 {"code_exception.java_2.code.Text": { $exists : true, $ne : ""} },//13294 {"code_exception.java_4.code.Text": { $exists : true, $ne : ""} }

Template Render is not passing pymongo aggregate variable to template

烈酒焚心 提交于 2019-12-11 16:37:44
问题 I am trying to pass a variable from pymongo on my views.py to a template. I am not getting any errors but neither is my code being rendered to my template. views.py: def gettheAudit(request): for x in mycol.aggregate([{"$unwind":"$tags"},{'$match': {'tags.tag.name':'A A',}},{'$project': {'url': 1, 'AR': 1, 'tags.tag.name': 1, 'tags.variables': 1, '_id': 0}},]): theURLs = x['url'] theNames = json.dumps(x['tags']['tag']['name']) theVs = json.dumps(x['tags']['variables']) template = loader.get