草庐IT

array_contains

全部标签

mongodb - meteor /MongoDB : Update an array item in a collection by index

这是我的收藏结构的概述:{profile:{first_name:'Plop',surname:'Plopette',...},medical_history:{significant_illnesses:['Asthma','Diabetes'],...}}如何访问和更新medical_history.significant_illnesses数组中的一项?我的失败很惨:Patients.update(Session.get("current_patient"),{$push:{"medical_history.significant_surgeries.surgeryIndex":

mongodb - 蒙戈 : Return specific fields from an array slice

我想从Mongo中的数组返回特定​​字段,但遇到了问题。假设我们有这样一个文档:{"student":"Bob","report_cards":[{"Year":2016,"English":"B","Math":"A"},{"Year":2015,"English":"B","Math":"A"}]}我想返回以下内容:{"Student":"Bob",{"English":"B"}}基本上,我只需要报告卡数组中的第一个元素,并且只返回英文字段。我知道它是周围的东西:db.collection.find({},{"Student":1,"report_cards":{$slice:1}

arrays - 如何在mongodb中连接数字和字符串值?

我需要从mongodb的json文件中的数组中选择一个值。json看起来像这样:{"key":{"subkey":"value","subkey1":"value","subkey2":"value","firstArray":[NumberLong(1234),"secondIndex"]}}我正在尝试选择firstIndex,我的查询如下所示:db.getCollection('table_name').aggregate([{$project:{columnName:{$concat:[{$substr:["$key.firstArray[0]"],"helloworld"}]}

arrays - Mongodb 集合转换

我有一个下面的集合看起来像一个普通的Rdbms表,所以为了获得Json和mongodb的优势,我想从一种形式转换为另一种形式我是MongoDB的新手。[{"ccp":1,"period":1,"sales":100,"units":50},{"ccp":1,"period":2,"sales":200,"units":50},{"ccp":2,"period":1,"sales":100,"units":50},{"ccp":2,"period":2,"sales":200,"units":50}]我希望将上面的集合转换为下面的格式[{"ccp":1,"periods":[{"peri

Node.js MongoDB 错误 : the update operation document must contain atomic operators

错误是:更新操作文档必须包含原子操作符。db.get().collection('users').updateOne(query,newvalues,function(err,result){cb(err,result)})我已经使用了$set运算符。我刚刚在控制台上打印了查询和新值,我找不到任何错误。query:{username:'macarra'}newvalues:{$set:{name:"MojoPicon",email:"mako@gmail.es"}} 最佳答案 如果您拥有具有新值的对象:varobj={name:"M

arrays - 在mongodb中的数组中查找最近的值

我有很多学生,每个学生在每个月的不同日子都被分配了家务。例如:{name:'Josh',choredays:[2,5,16,20,28]},{name:'Will',choredays:[5,15,18,21,22]}给定一个数字,我想在第二天将每个学生必须做的家务作为输出。例如,给定14,我想得到Josh16Will15如何在Mongo聚合中表达这一点? 最佳答案 你可以试试下面的聚合您需要使用$filter消除较少输入值的聚合运算符。然后使用$slice这消除了更大的值(value)。db.collection.aggregat

mongodb - Scala MongoDB,覆盖编解码器以写入/读取 Array[Byte]

我正在使用http://mongodb.github.io/mongo-scala-driver/我正在为一个CC定义编解码器。lazyvaluserInfoCodec:Codec[UserInfo]=newCodec[UserInfo]{overridedefencode(writer:BsonWriter,value:UserInfo,encoderContext:EncoderContext):Unit=???overridedefdecode(reader:BsonReader,decoderContext:DecoderContext):UserInfo=???}我在里面进行

arrays - 如何计算数组中每个值的出现次数?

我在MongoDB中有一个ISSUES的数据库,有些issue有评论,是一个数组;每个评论都有一个作者。如何统计每位作者发表的评论数?我试过了db.test.issues.group({key="comments.username":true;initial:{sum:0},reduce:function(doc,prev){prev.sum+=1},});但没有运气:(示例:{"_id":ObjectId("50f48c179b04562c3ce2ce73"),"project":"RubyDriver","key":"RUBY-505","title":"GETMOREissent

arrays - MongoDB 获取文档的部分数组

数据结构:{_id:'1','title:'Blabla',comments:[{id:'3',type:'normal'},{id:'4',type:'admin'},{id:'5',type:'admin'},{id:'6',type:'admin'}]}我想要得到的是一组最后5条评论的类型admin:{comments:[{id:4,type:'admin'},{id:'5',type:'admin'},{id:'6',type:'admin'}]}我尝试过的:db.collection('posts').find({_id:'1','comments.type':'admin'

c# - MongoDB c# 驱动程序 : Case Insensitive Compare using in or contains on a list using linq

我正在使用MongoDBC#驱动程序,我想在集合上执行一个linqwhere子句,将属性的小写版本与我在内存中的列表的小写版本进行比较。像这样;items=items.Where(i=>listToCheck.Contains(i.Property.ToLower()));我也试过...items=items.Where(i=>i.Property.ToLower().In(listToCheck));我认为这实际上是正确的并且应该有效,但可能尚未实现。我收到一条错误消息,指出与ToLower()命令相关的“不受支持的where子句”。据我所知,驱动程序目前无法完成此操作,因为它必须使