草庐IT

mongoid3

全部标签

ruby-on-rails - 如何使用 mongoid 构建管理 UI?

我正在将RoR3与mongoid一起使用,我希望通过activerecord获得一个简单的管理UI,例如typus或activescaffold。有什么提示吗?谢谢 最佳答案 您可以尝试将所需的功能贡献给:ActiveScaffold使用这些想法UsingActiveScaffoldOnADataStructure–NoDatabaseTablerails_admin使用这些想法issue105 关于ruby-on-rails-如何使用mongoid构建管理UI?,我们在StackOve

ruby-on-rails - 查找后的 Mongoid 文档持久性

我无法在mongoid中保存我的文档。我的Controller中有以下代码片段:params[:user][:residence_attributes][:locations_attributes].eachdo|num,location_attributes|zipcode=Location.find(location_attributes[:id])if!zipcode.update_attributes(location_attributes)puts"fail"fail=trueendputs"zipcodeagain#{zipcode}"puts"zipcodenumber#

mongodb - Mongoid 限制参数被忽略

我试图获取具有唯一值(first_name)的最新N条记录。到目前为止:@users=User.all(:limit=>5,:sort=>[:created_at,:desc]).distinct(:first_name)几乎可以工作..但忽略限制和排序顺序还有:@users=User.limit(5).desc(:created_at).distinct(:first_name)忽略'limit'和'desc'@users=User.limit(5)作品..我做错了什么?任何帮助将不胜感激! 最佳答案 我玩了一会儿,这是我能想到的

json - as_json 运行速度非常慢(Mongoid + Sinatra)

我将Sinatra(1.3.2)与Mongoid(2.4.10)结合使用。我注意到将大约350个mongo文档转换为JSON需要很长时间。我添加了一些基准包装器只是为了看看什么花费的时间最多:get'/games'docontent_type:textobj=nilt1=Benchmark.measure{@games=filtered_games.entries}t2=Benchmark.measure{obj=@games.as_json}t3=Benchmark.measure{obj.to_json}"Query:#{t1}\nToObject:#{t2}\nJSON:#{t3

ruby-on-rails - 具有不同 key 的 Mongoid upsert

是否可以使用字段的JSON/哈希值更新插入到mongodb集合中,而不是使用_idObjectId字段,而是使用不同的索引字段,例如external_id?我用它来更新我每天从Feed收到的一些项目,因此,Feed项目不包含我的内部ID。 最佳答案 是的,可以在Mongoid中使用自定义id进行更新,但仅限于2012年6月27日左右的3.0.0.rc。应用/模型/item.rbclassItemincludeMongoid::Documentfield:external_id,type:Stringfield:_id,type:St

ruby-on-rails - rails mongoid 中的多键索引

我想以这种格式存储数据。{"_id":ObjectId(...)"title":"GroceryQuality""comments":[{author_id:ObjectId(...)date:Date(...)text:"Pleaseexpandthecheddarselection."},{author_id:ObjectId(...)date:Date(...)text:"Pleaseexpandthemustardselection."},{author_id:ObjectId(...)date:Date(...)text:"Pleaseexpandtheoliveselect

ruby - Has_and_belongs_to_many 索引mongoid

我在用户和项目之间建立了多对多关系,而且它工作得很好。但是我想在mongoid中模拟这种情况:db.projects.insert({"name":"Testproject","memberships":[{"user_id":ObjectId("4d730fcfcedc351d67000002"),"role":"administrator"},{"role":"editor","user_id":ObjectId("4d731fe3cedc351fa7000002")}]})我阅读了Mongoid的文档,对于关系我必须这样做:has_and_belongs_to_many:pref

php - 使用 mongoID 数组查询集合

我有以下代码://company_idsisanarrayofmongoIDs//company_idisanarray(withonly1element)ofmongoIDforeach($company_idsas$company_id){$results=Archive::where("billing.company._id",'all',array($company_id))->get();...这是Log::info(print_r($company_ids,true))的输出[2016-10-2202:41:27]production.INFO:Array([0]=>575

ruby-on-rails - 如何在 mongoid 中使用或条件进行查询

如何在Mongoid中使用或条件进行查询。 最佳答案 这是mongoid中“OR”查询的解决方案。如果你想要像下面这样的查询select*fromuserwhereid=10orname='hitesh';在带有mongoid的rails中,你必须像这样编写查询User.any_of({id:10},{name:'hitesh'}).first 关于ruby-on-rails-如何在mongoid中使用或条件进行查询,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails-3 - Mongoid 与设计的关系

我有一些带有MongoDB、Mongoid映射器和设计的Rails应用程序。А授权用户可以创建、编辑、删除帖子(脚手架)和评论此帖子。我以RyanBates截屏视频的评论模型为例,第238集“Mongoid”。评论.rbclassCommentincludeMongoid::Documentfield:namefield:contentembedded_in:post,:inverse_of=>:commentsend后.rbclassPostincludeMongoid::Documentfield:namefield:contentvalidates_presence_of:nam