pymongo

why DuplicateKeyError: E11000 duplicate key error index: test.test.$notification_1 dup key: { : null }

我怕爱的太早我们不能终老 提交于 2019-12-07 12:48:16
问题 i create unique index like this: self.db_database[co_name].ensure_index([('src_md5',-1),('src_time',-1),('src_size',-1)],unique=True) self.db_database[co_name].ensure_index(('notification'),unique=True) self.db_database[co_name].ensure_index(('version'),unique=True)` before insert i creat a record as follows: self.db_database[co_name].insert({"notification":"yes","file_md5":-1,"file_size":-1,"file_time":-1,"bypass":0,"server_list":[],"ok_to_download":0,"force_to_download":-1,"idx":0},safe

What exactly is wrong with using pymongo in twisted?

◇◆丶佛笑我妖孽 提交于 2019-12-07 12:38:58
问题 I have a twisted server application that maintains persistent connections with around 1000 clients. Each client will occasionally send data to my twisted server, and I would like that server to store data into a MongoDB database. So far, so good. But, the pymongo documentation states something like "there is no good way to use pymongo with twisted". I don't understand why not. Can someone please explain what exactly the problem is and what the pitfalls are? I think it has something to do with

Mongodb Read preferences

☆樱花仙子☆ 提交于 2019-12-07 12:00:35
SETUP: I have one PRIMARY and two SECONDARY instances of mongodb. One of the two secondary instances is hosted in the same region as my web app. I am using pymongo for connecting. QUERY: How can I get connection to a SECONDARY with lower latency. Currently I am doing this: from pymongo import ReplicaSetConnection from pymongo import ReadPreference db = ReplicaSetConnection('localhost:27017', replicaSet='rs1')['my_db'] db.read_preference = ReadPreference.SECONDARY I get a connection to any one of the SECONDARY. How can I force to get connection from the instance with lower latency Thanks!! The

Project different embedded structures to same name

岁酱吖の 提交于 2019-12-07 11:41:37
问题 I am writing a python script that performs these tasks: Query a MongoDB Collection with embeded documents Aggregate and Project to change the field names that are returned in the query to match a "u_" convention Import the values to ServiceNow via REST API ISSUE: The embedded documents are not in a consistent structure. The HOSTNAME field is stored in varying structures. I need to return the hostname as u_hostname. I need the value of $hostnames.name if it exists OR the value of $hostname if

Pip says that pymongo has been installed, but doesn't show it as installed

99封情书 提交于 2019-12-07 11:10:49
问题 I'm trying to install pymongo in a virtual environment, and pip says that it's installed, but it doesn't appear to be: (venv)$ ./myapp.py Traceback (most recent call last): File "./myapp.py", line 5, in <module> import myAppMongo File "/home/me/python/myapp/myAppMongo.py", line 4, in <module> from pymongo import MongoClient ImportError: No module named 'pymongo' I've installed pymongo: (venv)$ pip --no-cache install pymongo Collecting pymongo Downloading pymongo-3.2.tar.gz (473kB) 100% |█████

pymongo和mongoengine安装和使用教程 包含常用命令行和代码示例 | pymongo and mongoengine tutorial on ubuntu 16.04

依然范特西╮ 提交于 2019-12-07 09:34:24
本文首发于个人博客 https://kezunlin.me/post/e88f04e5/ ,欢迎阅读最新内容! pymongo and mongoengine tutorial on ubuntu 16.04 Guide version mongo 2.6.10 mongo gui: robo3t-1.3.1 pymongo 3.9.0 MongoEngine 0.18.2 install mongodb sudo apt-get install -y mongodb mongo shell mongo --host mongodb0.example.com --port 27017 mongo --version MongoDB shell version: 2.6.10 see mongo shell > mongo # show all dbs > show dbs # display current db >db test (default database) # switch or create db > use mydb > db.help() > show collections posts system.indexes > db.posts.help() > db.posts.find() help on db and collections >db

pymongo和mongoengine安装和使用教程 包含常用命令行和代码示例

二次信任 提交于 2019-12-07 09:26:26
本文首发于个人博客 https://kezunlin.me/post/e88f04e5/ ,欢迎阅读最新内容! pymongo and mongoengine tutorial on ubuntu 16.04 Guide version mongo 2.6.10 mongo gui: robo3t-1.3.1 pymongo 3.9.0 MongoEngine 0.18.2 install mongodb sudo apt-get install -y mongodb mongo shell mongo --host mongodb0.example.com --port 27017 mongo --version MongoDB shell version: 2.6.10 see mongo shell > mongo # show all dbs > show dbs # display current db >db test (default database) # switch or create db > use mydb > db.help() > show collections posts system.indexes > db.posts.help() > db.posts.find() help on db and collections >db

Python Pymongo auth failed

梦想与她 提交于 2019-12-07 08:21:58
问题 Pymongo keep failing to login MongoDB. I typed right password for "root" account. Traceback (most recent call last): File "index.py", line 3, in <module> from apis import app File "/home/app/apis/__init__.py", line 16, in <module> import apis.call File "/home/app/apis/call.py", line 12, in <module> import auth File "/home/app/apis/auth.py", line 18, in <module> connection.api.authenticate(database.ADMIN_ID,database.ADMIN_PASSWD) File "/usr/lib64/python2.6/site-packages/pymongo/database.py",

Show database in mongodb show it empty while I can acess and query data

落爺英雄遲暮 提交于 2019-12-07 07:49:46
问题 While accessing the database in command line, the 'show dbs' list all the existing databases showing the one I want to access as empty . EDIT: Neverless using the database and running db.stats() it show the correct size of data. The output of show dbs : db1 (empty) db2 (empty) db3 0.999755859375GB db_5 (empty) But I can access, query, count and show the data stored in db_5. Can someone explain me why this is shown as empty? Can I export it correctly without loosing data? EDIT : After export

OperationFailure: database error when threading in MongoEngine/PyMongo

痞子三分冷 提交于 2019-12-07 06:40:15
问题 I have a function that will read data from a website, process it, and then load it into MongoDB. When I run this without threading it works fine but as soon as I set up celery tasks that just call this one function I frequently get the following error: "OperationFailure: database error: unauthorized db:dbname lock type:-1" It's somewhat odd because if I run the non-celery version on multiple terminals, I do not get this error at all. I suspect it has something to do with there not being an