我使用脚本来删除mongo上的重复项,它在我用作测试的10个项目的集合中工作但是当我使用600万个文档的真实集合时,我收到错误.
这是我在Robomongo(现在称为Robo 3T)中运行的脚本:
var bulk = db.getCollection('RAW_COLLECTION').initializeOrderedBulkOp();
var count = 0;
db.getCollection('RAW_COLLECTION').aggregate([
// Group on unique value storing _id values to array and count
{ "$group": {
"_id": { RegisterNumber: "$RegisterNumber", Region: "$Region" },
"ids": { "$push": "$_id" },
"count": { "$sum": 1 }
}},
// Only return things that matched more than once. i.e a duplicate
{ "$match": { "count": { "$gt": 1 } } }
]).forEach(function(doc) {
var keep = doc.ids.shift(); // takes the first _id …
Run Code Online (Sandbox Code Playgroud) 我的问题是如何通过pymongo验证mongodb身份验证的用户名密码?.
我正在尝试使用PyMongo 3.2.2和包含用户和密码的URL连接到MongoDB实例,如MongoDB Docs中所述.不同的是我使用的密码包含'@'.
起初我只是试图连接而不逃避,像这样:
prefix ='mongodb://'
user ='user:passw_with _ @ _'
suffix ='@ 127.0.0.1:27001 /'
conn = pymongo.MongoClient(前缀+用户+后缀)
当然我得到以下错误:
InvalidURI: ':' or '@' characters in a username or password must be escaped according to RFC 2396.
Run Code Online (Sandbox Code Playgroud)
所以我尝试转义用户:使用urllib.quote()传递部分,如下所示:
prefix ='mongodb://'
user = urllib.quote('user:passw_with _ @ _')
suffix ='@ 127.0.0.1:27001 /'
conn = pymongo.MongoClient(前缀+用户+后缀)
但后来我得到了:
OperationFailure: Authentication failed.
Run Code Online (Sandbox Code Playgroud)
(重要的是说使用GUI MongoDB管理工具(Robomongo,如果这很重要)我可以使用(真实)地址和凭证连接到MongoDB.)
在上面的代码中打印用户变量生成一个'user:passw_with_%40_'
字符串(即'@'变为'%40')并根据维基百科那是预期的转义.
我甚至试图逃逸单,双反斜杠(中@ user = 'user:passw_with_\\@_'
和user = 'user:passw_with_\@_' …
我最近开始使用EncFS来保护我雇主的代码(如果我的笔记本电脑被盗).但是,当我启动PyCharm时,我现在得到以下警告(每次):
外部文件更改同步可能很慢 项目文件无法监视(它们是否在网络安装下?)
这些文件位于本地安装上.我想EncFS会引入一些开销,但我希望它可以忽略不计.我如何说服PyCharm不再担心它并将它们视为本地文件?
(作为最后的手段,我每次开始时如何停止此警告?)
简而言之,我的问题是:如果一个方法被多次调用,在内存消耗方面是否更好,使其无效并使用List作为参数来返回其值?如果真的能节省内存,那么代码难以阅读是不是一种糟糕的做法?
让我举一个例子来说明一点.假设我有一辆车,每辆车都必须属于一个品牌.我有一个方法可以从品牌列表中返回所有汽车,这种方法使用foreach和方法从一个品牌中检索所有汽车.如下代码:
private List<Car> getCarsByBrands(List<Brand> brands) {
List<Car> result = new Arraylist<>;
for(Brand brand : brands) {
result.add(getCarsBySingleBrand(brand))
}
return result;
}
private List<Car> getCarsBySingleBrand(Brand brand) {
List<Car> result = new Arraylist<>;
result.add(retrieveCarsByBrand(brand)) // retrieveCarsByBrand omitted
return result;
}
Run Code Online (Sandbox Code Playgroud)
我的一位同事辩护说,方法getCarsBySingleBrand应该被重写为无效并使用List作为参数,这个列表将包含所有的汽车,如下所示:
private List<Car> getCarsByBrands(List<Brand> brands) {
List<Car> result = new Arraylist<>;
for(Brand brand : brands) {
getCarsBySingleBrand(result, brand))
}
return result;
}
private void getCarsBySingleBrand(List<Car> …
Run Code Online (Sandbox Code Playgroud) 我在Windows 7机器上安装了Pycharm社区版2016.1.4,并尝试更新我打算使用的项目所使用的一些软件包.更新失败,因为本地存储库" 不受信任或安全主机 "(根据pip),所以要更新我需要运行的命令行中的包:
pip install <package> --trusted-host <insecure-host>
Run Code Online (Sandbox Code Playgroud)
是否有可能在PyCharm中指定--trusted-host选项或Pycharm如此关注我的安全性,它不允许我这样做?
我有几个使用迭代来搜索正确答案的数学算法.这是一个例子:
def Bolzano(fonction, a, b, tol=0.000001):
while abs(b - a) > tol:
m = (a + b) / 2
if sign(fonction(m)) == sign(fonction(a)):
a = m
else:
b = m
return a, b
Run Code Online (Sandbox Code Playgroud)
我想计算算法通过循环得到a和b的次数.但是这不是一个for
函数而且它不是一个列表,所以如果我使用的话,我无法清楚地指出我想要计算的对象enumerate
.有没有办法计算这些循环?
注意:我不是要尝试更改代码本身.我正在寻找一种计算循环迭代的方法while
,然后我可以将其用于其他情况.
python ×3
mongodb ×2
pycharm ×2
count ×1
duplicates ×1
filesystems ×1
java ×1
loops ×1
methods ×1
packages ×1
pymongo-3.x ×1
return-type ×1
ubuntu-13.10 ×1