草庐IT

sort_key

全部标签

mongodb - 蒙哥错误: E11000 duplicate key error collection for unique compound index

Questionisrelatedtouniquecompoundindexunlikeothersuchquestionswhichhaveuniqueindexonly.Ialsohavesparse:truefortheindexes.我的收藏中有以下索引[{"v":2,"key":{"_id":1},"name":"_id_","ns":"somedb.votes"},{"v":2,"key":{"answerId":1},"name":"answerId_1","ns":"somedb.votes","sparse":true,"background":true},{"v":

ruby-on-rails-3 - Rails 3 和 mongoid : How would you about sorting/grouping collect to display as a 2 dimension table?

我有很多字段的用户模型,我想显示一个表作为其中2个字段的矩阵:-创建时间-类型对于created_at,我只是这样使用了一个group_by:(User.where(:type=>"blabla").all.group_by{|item|item.send(:created_at).strftime("%Y-%m-%d")}).sort.eachdo|creation_date,users|这给了我每个创建日期的所有用户的一个很好的数组,所以我table上的线条没问题。但是我想显示多行,每个代表每种类型的用户的子选择。所以目前,我每行执行一个请求(每种类型,只需替换“blabla”)。

node.js - MongoDB 聚合 : Sorting by existing values first

我的用户有这个字段:interestedIn:[{type:String,enum:['art','sport','news','calture',...],}],我的视频有这个字段:categories:[{type:String,enum:['art','sport','news','calture',...],}],所以我需要一个具有以下条件的视频查询:首先查询所有视频并按req.user.interestedIn中的值排序。其余与req.user.interestedIn不匹配的视频排在最后。我已经完成了上述查询:Video.aggregate([{'$match':{}},{

mongodb - Mongodb 聚合创建输出为 {"key": "value"} from 2 arrays

我有一个关于如何从2个数组创建输出的问题,一个数组带有翻译键,另一个数组带有翻译,我将输出为"translation_key":"value"当前输出:{"_id":ObjectId("5bfc0b2b30c4683f585078fb"),"translation":["hour","day"],"translation_key":["HOUR_TEXT","DAY_TEXT"],"locale_id":"EN_en"}输出应该是:{"EN_en":{"HOUR_TEXT":"hour","DAY_TEXT":"day",}} 最佳答案

mongodb - 在 MongoDB 中使用 "_id"插入 key 是否合适?

我正在使用MongoDB构建数据库。我找到了两种在pymongo中插入键的方法。r.insert({'id':'1234','feats':'abcd'})和r.insert({'_id':'1234','feats':'abcd'})MongoDB中的结果如下:{"_id":ObjectId("51c27f8737450f1d517c1ec4"),"id":"1234","feats":"abcd"}和{"_id":"1234"),"feats":"abcd"}由于对MongoDB经验不多,所以我不知道'_id'的用法。我认为第二种在MongoDB中插入的方法现在更简单。将来会不会引

java - Spring 数据蒙戈 : How to save batch ignoring all duplicate key errors?

我有以下域对象:@DocumentclassFoo{@IdprivatefinalStringbar;privatefinalStringbaz;//getters,setters,constructoromitted}插入如下:Collectionfoos=...;mongoTemplate.insert(foos,Foo.class);如何在忽略所有重复键异常的情况下在一次调用中保存所有结果? 最佳答案 在我的例子中,像@marknorkin的回答那样允许修改/覆盖现有文档是不合适的。相反,我只想插入新文档。我使用MongoOp

mongodb 使用 forEach 更新所有文档的 key

我想在Mongo中更新我所有文档的“顺序”字段,以便它们为1..2..3..4....34。运行后,它们都有“order”:“34”。我做错了什么?vari=1;db.images.find().forEach(function(){db.images.update({},{"$set":{"order":NumberInt(i)}},{multi:true});i++;}) 最佳答案 multi:true表示匹配查询的所有文档都将被更新。您的查询是{},它匹配所有文档。因此,基本上您是在每次迭代中更新所有文档的顺序。此外,snap

mongodb - 我可以在 MongoDB 聚合框架 $sort 上使用 2 个以上的字段吗?

使用以下PyMongo查询。我使用了Mongo网络研讨会中的一些技巧,他们建议使用_id字段存储时间戳,以提高性能和内存使用率。cursor=db.dados_meteo_reloaded.aggregate([{"$match":{"_id":{"$gte":"0001:20120901","$lte":"0001:20140215"},"TMP":{"$lt":7.2}}},{"$project":{"year":{"$substr":["$_id",5,4]},"month":{"$substr":["$_id",9,2]},"day":{"$substr":["$_id",11

node.js - 蒙哥错误: must have $meta projection for all $meta sort keys using Mongo DB Native NodeJS Driver

直接在MongoDB上运行以下文本搜索不会产生任何问题:db.getCollection('schools').find({$text:{$search:'somequerystring',$caseSensitive:false,$diacriticSensitive:true}},{score:{$meta:"textScore"}}).sort({score:{$meta:"textScore"}})然而,当尝试使用nativeNodeJSdriver运行相同的查询时:functiongetSchools(filter){returnnewPromise(function(res

mongodb - key 不得包含 . pymongo 中的错误

我正在尝试通过pymongo获取serverStatus命令的输出,然后将其插入到mongodb集合中。这是字典{u'metrics':{u'getLastError':{u'wtime':{u'num':0,u'totalMillis':0},u'wtimeouts':0L},u'queryExecutor':{u'scanned':0L},u'record':{u'moves':0L},u'repl':{u'buffer':{u'count':0L,u'sizeBytes':0L,u'maxSizeBytes':268435456},u'apply':{u'batches':{u'