草庐IT

count_num

全部标签

javascript - MongoDB MapReduce,仅当 count > 1 时返回

我在MongoDB中有数据。一个对象的结构是这样的:{"_id":ObjectId("5395177980a6b1ccf916312c"),"institutionId":"831","currentObject":{"systemIdentifiers":[{"value":"24387","system":"ABC"}]}}我必须知道有多少对象具有相同的institutionId和systemIdentifiers[0].value并且只想返回以这种方式重复的对象。为此,我按这些ID将它们分组并计算出现次数。当count大于1时,应返回对象(一对ID)。这是一段使用MapReduc

mongodb - 蒙戈新手: Count of entries where the latest sub-hash has a value within a time range

我有一个mongo存储“任务”,它有一个数组“answers”,它采用散列,其元素是时间戳。所以:task->project_id,answers->[{timestamp:,question_1:,question_2:},{timestamp:,question_1:,question_2:},]我想做的是获取具有给定项目ID且其最新答案时间戳字段在过去24小时内的所有任务的列表。项目ID的事情显然非常简单,我可以确定时间戳是否落在$gte和$lt的给定时间段之间......但我不知道如何将其范围限定为最新的时间戳。我没有为此使用ORM-所以只是首选普通的mongo查询语法。感谢任

mongodb - 蒙戈聚合 : Sum Count Field of Duplicate Array Value Field

我有一大堆这样的文件:{_id:'1',colors:[{value:'red',count:2},{value:'blue',count:3}]shapes:[{value:'cube',type:'3d'},{value:'square',type:'2d'}]},{_id:'2',colors:[{value:'red',count:7},{value:'blue',count:34},{value:'yellow',count:12}]shapes:[{value:'prism',type:'3d'},{value:'triangle',type:'2d'}]}通过使用$unw

mongodb - 高级数据聚合 : counting average in MongoDB collections

我有一组文档,例如:{"browser":"firefox","version":"4.0.1"}{"browser":"firefox","version":"3.6.2"}{"browser":"ie","version":"8.0"}如何计算所有浏览器的平均值以便结果为:globalfirefox:66%globalie:33%precisefirefox:4.0.1:50%3.6.3:50%棘手的部分是我不想在数组中提供所有可用的Firefox版本。MongoDB查询应该找到集合中的所有不同版本并计算所有版本的平均值。提前致谢! 最佳答案

php - mongodb num_rows 相当于 php

如何获取结果的数量,相当于mongodb中的num_rows(mysqli)?如果我有$db->$dbName->find(array("email"=>$newemail,"password"=>$newpass));检查符合此条件的结果数量的最佳方法是什么?在mysqli中我会做类似的事情$sql="SELECTidFROMtableWHEREemail='%s'ANDpassword='%s'";$query=sprintf($sql,$newemail,$newpass);$result=$conn->query($query);$rows=$result->num_rows;

mongodb map 减少 value.count

在mongodb中,我有一个map函数,如下所示:varmap=function(){emit(this.username,{count:1,otherdata:otherdata});}和减少功能如下:varreduce=function(key,values){values.forEach(function(value){total+=value.count;//notethisline}return{count:total,otherdata:values[0].otherdata};//pleaseignoreotherdata}问题出在注释的行上:total+=value.c

c# - MongoCursor.Count 与... IAsyncCursor.Count?

有谁知道旧版MongoCursor的等效“计数”方法在哪里,但在新驱动程序(IAsyncCursor)中?或者有人知道如何使用2.0异步驱动程序/方法复制它吗?想法是通过分页(跳过和限制)查询文档,并且只有一次数据库命中,获取文档,返回文档的计数以及在没有LIMIT的情况下找到的所有文档的计数使用MongoDBC#遗留驱动程序,我曾经这样做过:MongoCursorresult=collection.FindAs(query);result.setSkip(20);result.setLimit(10);varsaleOrders=result.ToList();//'limited'

MongoDB db.collection.count() 与 db.collection.find().length()

我想了解为什么这些命令在针对同一个MongoDB集合从mongos实例运行时返回不同的数字?db.users.count()db.users.find().length()可能是什么原因,是否可能是潜在问题的征兆? 最佳答案 我相信你的收藏是分片的。大多数分片数据库解决方案都有这样的差异,因为有些命令会考虑整个集合,即所有分片的所有文档,而其他一些命令只考虑它所连接的分片的文档。这是要时刻牢记的事情。它主要适用于以下命令:计数返回给定字段具有最低值的文档返回给定字段具有最大值的文档...在Mongo上找到docs:count()is

python - Pymongo replace_one modified_count 总是 1 即使没有改变任何东西

为什么以及如何能这样工作?item=db.test.find_one()result=db.test.replace_one(item,item)print(result.raw_result)#Gives:{u'n':1,u'nModified':1,u'ok':1,'updatedExisting':True}print(result.modified_count)#Gives1当mongodbshell中的等价物总是0item=db.test.findOne()db.test.replaceOne(item,item)#Gives:{"acknowledged":true,"ma

内部数组的 Mongodb count()

我有以下MongoDB集合db.students:/*0*/{"id":"0000","name":"John""subjects":[{"professor":"Smith","day":"Monday"},{"professor":"Smith","day":"Tuesday"}]}/*1*/{"id":"0001","name":"Mike""subjects":[{"professor":"Smith","day":"Monday"}]}我想查找给定学生的科目数。我有一个问题:db.students.find({'id':'0000'})这将返回学生文档。我如何找到“主题”的计