pymongo

Select based on timestamp and update timestamp with zero

你说的曾经没有我的故事 提交于 2019-12-18 07:15:18
问题 How do I select records from a date field which has a time (HH:MM:SS.Milisecond) value greater than zero from a MongoDB collection and update it with a time (HH:MM:SS) value as zero by keeping the date value the same as the existing value in a Python script? The current data would look like as below - 1) "createdDate" : ISODate("2015-10-10T00:00:00Z") 2) "createdDate" : ISODate("2015-10-11T00:00:00Z") 3) "createdDate" : ISODate("2015-10-12T00:00:00Z") 4) "createdDate" : ISODate("2015-10-13T01

Select based on timestamp and update timestamp with zero

為{幸葍}努か 提交于 2019-12-18 07:15:01
问题 How do I select records from a date field which has a time (HH:MM:SS.Milisecond) value greater than zero from a MongoDB collection and update it with a time (HH:MM:SS) value as zero by keeping the date value the same as the existing value in a Python script? The current data would look like as below - 1) "createdDate" : ISODate("2015-10-10T00:00:00Z") 2) "createdDate" : ISODate("2015-10-11T00:00:00Z") 3) "createdDate" : ISODate("2015-10-12T00:00:00Z") 4) "createdDate" : ISODate("2015-10-13T01

failure to import pymongo ubuntu

谁说胖子不能爱 提交于 2019-12-18 05:57:33
问题 I am currently runnning Ubuntu 12.04 with mongodb 2.2 and pymongo version 2.3. I am attempting to gather some information using Twitters API and I am getting an error when attempting to import mymongo. Here is what I have: import pycurl, json import pymongo STREAM_URL = "https://stream.twitter.com/1/statuses/filter.json" WORDS = "track=#obama" USER = "myuser" PASS = "mypass" ImportError: No module named pymongo Any ideas? 回答1: I had the same problem. Pymongo conflicts with the bson package.

MongoDB/PyMongo: how to 'escape' parameters in regex search?

▼魔方 西西 提交于 2019-12-18 04:55:22
问题 I'm using pymongo and want to do a search for items starting with a certain sequence of characters. I might implement that like this: items = collection.find({ 'key': '/^text/' }) This should work, but what if text is a variable? I could do something like: items = collection.find({ 'key': '/^' + variable + '/' }) But now if the text in variable contains any characters with special regex meaning (such as $ ), the query no longer behaves as expected. Is there a way to do some sort of parameter

MongoDB query to return only embedded document

ε祈祈猫儿з 提交于 2019-12-17 18:29:03
问题 assume that i have a BlogPost model with zero-to-many embedded Comment documents. can i query for and have MongoDB return only Comment objects matching my query spec? eg, db.blog_posts.find({"comment.submitter": "some_name"}) returns only a list of comments. edit: an example: import pymongo connection = pymongo.Connection() db = connection['dvds'] db['dvds'].insert({'title': "The Hitchhikers Guide to the Galaxy", 'episodes': [{'title': "Episode 1", 'desc': "..."}, {'title': "Episode 2", 'desc

Append item to MongoDB document array in PyMongo without re-insertion

≡放荡痞女 提交于 2019-12-17 16:05:25
问题 I am using MongoDB as the back-end database for Python web application (PyMongo + Bottle). Users can upload files and optionally 'tag' these files during upload. The tags are stored as a list within the document, per below: { "_id" : ObjectId("561c199e038e42b10956e3fc"), "tags" : [ "tag1", "tag2", "tag3" ], "ref" : "4780" } I am trying to allow users to append new tags to any document. I came up with something like this: def update_tags(ref, new_tag) # fetch desired document by ref key as

How to convert a pymongo.cursor.Cursor into a dict?

只愿长相守 提交于 2019-12-17 15:38:18
问题 I am using pymongo to query for all items in a region (actually it is to query for all venues in a region on a map). I used db.command(SON()) before to search in a spherical region, which can return me a dictionary and in the dictionary there is a key called results which contains the venues. Now I need to search in a square area and I am suggested to use db.places.find , however, this returns me a pymongo.cursor.Cursor class and I have no idea how to extract the venue results from it. Does

How to sort mongodb with pymongo

余生颓废 提交于 2019-12-17 06:26:12
问题 I'm trying to use the sort feature when querying my mongoDB, but it is failing. The same query works in the MongoDB console but not here. Code is as follows: import pymongo from pymongo import Connection connection = Connection() db = connection.myDB print db.posts.count() for post in db.posts.find({}, {'entities.user_mentions.screen_name':1}).sort({u'entities.user_mentions.screen_name':1}): print post The error I get is as follows: Traceback (most recent call last): File "find_ow.py", line 7

search by ObjectId in mongodb with pymongo

若如初见. 提交于 2019-12-17 04:27:20
问题 I need to search an ObjectId with python using pymongo but I always get this error. Any ideas how to search? import pymongo from pymongo import MongoClient from pymongo import ObjectId gate = collection.find({'_id': ObjectId(modem["dis_imei"])}) print gate Traceback (most recent call last): File "C:\Users\gerswin\Documents\Proyectos\Demonio py\test.py", line 2, in <module> import pymongo File "C:\Python27\lib\site-packages\pymongo\__init__.py", line 80, in <module> from pymongo.connection

Performing regex Queries with pymongo

别说谁变了你拦得住时间么 提交于 2019-12-17 02:55:10
问题 I am trying to perform a regex query using pymongo against a mongodb server. The document structure is as follows { "files": [ "File 1", "File 2", "File 3", "File 4" ], "rootFolder": "/Location/Of/Files" } I want to get all the files that match the pattern *File. I tried doing this as such db.collectionName.find({'files':'/^File/'}) Yet i get nothing back , am i missing something because according to the mongodb docs this should be possible. If I perform the query in the mongo console it