【问题标题】:pymongo.errors.OperationFailure saying ns does not existpymongo.errors.OperationFailure 说 ns 不存在
【发布时间】:2015-03-04 04:11:28
【问题描述】:

我收到如下错误: Traceback(最近一次调用最后一次):

pymongo.errors.OperationFailure: 命令 SON([('mapreduce', u'tweets'), ('map', Code('function() { emit(this.via, 1); }', {})), ('reduce', Code(' function(key,value) {\n var res = 0;\n values.forEach(function(v) {res += 1 })\n return {count: res};\n }\n ', {})), ('out', 'via_count')]) 在命名空间 Corpus.$cmd 失败:ns 不存在

代码是:

   from pymongo import MongoClient
   from bson.code import Code
   con = MongoClient()
   db     = con.Corpus
   tweets = db.tweets
   map    = Code("function() { emit(this.via, 1); }")
   reduce = Code(""" function(key,value) {
       var res = 0;
       values.forEach(function(v) {res += 1 })
       return {count: res};
    }
    """)

    result = tweets.map_reduce(map, reduce, "via_count")
    for doc in db.via_count.find():
        print(doc)

【问题讨论】:

  • 这有什么更新吗?我遇到了同样的错误

标签: mapreduce


【解决方案1】:

在命名空间 Corpus.$cmd 上失败:ns 不存在

这意味着您在 Corpus 中没有名为“tweets”或“via_count”的集合。

与 mongodb 中的原始查询不同,map_reduce 函数在不存在时不会创建新集合。

【讨论】:

  • 一些带有解释的例子会很棒。
【解决方案2】:

即使数据库不存在也会报同样的错误

【讨论】:

  • 这是回答问题,还是评论/单独的问题?
  • 这是一个评论,是对答案的增强。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-03
  • 2011-09-06
  • 1970-01-01
  • 2017-01-17
  • 2014-07-18
  • 1970-01-01
  • 2017-03-01
相关资源
最近更新 更多