Tag: mongodb

何时索引,在Mongoid中索引什么?

我对索引有点新意,但我对索引的用例感到好奇。 (我假设它对索引字段的查询速度要快得多。)是否有标准来确定索引内容和索引时间? 我应该期待什么样的性能优势 – 特别是在Rails应用程序中使用Mongoid和MongoDb?

如何在Mongoid中更改文档的_type?

我在Rails应用程序中有以下模型: class User include Mongoid::Document … end class Admin < User … end 我得到一个用户: u = User.find(some_key) 并尝试更改_type: u._type # => “User” u._type = “Admin” u.save u._type # => “Admin” 但是,如果我重新加载对象,它仍然是一个用户: u.reload u._type = “User” 改变这个的正确方法是什么?

即使nested_attributes无效,update_attributes也始终返回true

我有2个嵌套数据模型: class Goodtender include Mongoid::Document include Mongoid::Timestamps field :name field :count references_many(:offerprices, :autosave => true) accepts_nested_attributes_for :offerprices, :allow_destroy => true, :reject_if => :all_blank validates_presence_of :name, :message => “Invalid” validates_numericality_of :count, :message => ‘Invalid’ validates_associated :offerprices, :message => ‘Invalid’ end class Offerprice include Mongoid::Document include Mongoid::Timestamps field :summ field :date_delivery, :type => DateTime field :note referenced_in […]

mongodb:将对象ID转换为BSON :: ObjectId

我们最近将我们的应用程序升级到Rails3,我们现在使用Mongoid,我们在使用_id从mongo-db检索以前的文档时遇到问题。 经过仔细调查,旧记录(我无法通过_id检索)如下所示: # 良好的记录具有以下结构: # 如您所见, _id字段不同。 对于旧记录,它似乎只是一个字符串,对于新记录,它是一个BSON::ObjectID 。 我似乎无法使用旧格式检索记录。 试图找到使用的记录 Audit::Log.where(:_id => BSON::ObjectId(‘4d892bfe6bcaff4ffd000001’)).first Audit::Log.where(:_id => ‘4d892bfe6bcaff4ffd000001′).first 两者都nil 。 但是对于良好的记录,我可以做到 Audit::Log.where(:’_id’ => ‘4e14152d6bcaff26bb000039’).first 我猜,但也许Mongoid会自动将字符串转换为ObjectId以便在_id上找到? 我看到的唯一修复方法是将所有_id -fields转换为BSON::ObjectId如果它们还没有)。 但是我该怎么做? 或者你有更好的方法吗?

Rails – MongoDB(Mongoid)存储数据库和日志的位置?

我是MongoDB和Mongoid的新手 ,我正在使用Debian测试( jessie/sid )。 当我打开/etc/mongodb.conf ,没有关于Mongoid存储db和logs的位置的信息。 它只是提到了logpath=/var/log/mongodb/mongodb.log 同样在config/mongoid.yml中没有有用的信息: development: sessions: default: hosts: – localhost:27017 database: project_development 如何在磁盘上找到project_development db并为该数据库记录日志? 那个地方有设置吗?

mongodb读/写性能和mongo托管在云端

我们目前正在与facebooker(Facebook游戏)开发高流量轨道应用程序。 由于amazon simpledb(aws-sdb)非常慢,我们正在考虑使用mongoHQ提供的专用mongodb服务器。 问题: 在amazon ec2实例上运行的mongodb服务器的读/写峰值是多少? 使用mongodb的ec2托管应用程序的推荐设置是什么 – 亚马逊EBS上的主人和ec2实例上的副本? 任何例子或经验? 有没有一家公司在云端提供mongodb托管服务? 谢谢,mz

连接被拒绝 – 在Mongodb上使用rake db:seed连接(2)

我正在使用rails 3.2和mongoid 。 我为设置数据库做了以下步骤: // Add an Admin User (to the admin db) use admin db.addUser(“theadmin”, “anadminpassword”) // Use your database use superuser // Add a user (to your database) db.addUser(“John”, “passwordForJohn”) // show all users: db.system.users.find() // add readonly user (kinda cool) db.addUser(“readonly”, “passwordForJohn”, true) 在我的mongo.yml我有: production: host: localhost port: 27017 username: John password: […]

如何以编程方式获取Mongoid写入的当前数据库?

我使用Mongoid和rails使用Mongoid.override_database(“database_name”)与多个数据库进行通信。 如何以编程方式查找当前数据库? 关于会话的Mongoid文档: http ://mongoid.org/en/moped/docs/driver.html定义覆盖数据库的方法,但没有定义获取当前正在使用的数据库的方法。

通过Mongoid / MongoDB建模多对多:

我对Mongoid / MongoDB比较新,我对如何建立特定的多对多关系有疑问。 我有一个User模型和一个Project模型。 用户可以属于许多项目,每个项目成员资格包括一个角色(例如“管理员”,“编辑者”或“查看者”)。 如果我使用ActiveRecord,那么我将使用has_many :through在User和Project之间建立多对多关联,然后我会在连接表中放置一个角色字段。 在MongoDB中为这个场景建模的好方法是什么?如何使用Mongoid声明该模型? 下面的示例似乎是一个很好的模型,但我不知道如何优雅地声明User和嵌入式ProjectMembership与Mongoid之间的关系关联。 提前致谢! db.projects.insert( { “name” : “Test project”, “memberships” : [ { “user_id” : ObjectId(“4d730fcfcedc351d67000002”), “role” : “administrator” }, { “role” : “editor”, “user_id” : ObjectId(“4d731fe3cedc351fa7000002”) } ] } ) db.projects.ensureIndex({“memberships.user_id”: 1})

Mongoid w / Rails,attr_accessible – >“找不到方法”

生成的Rails应用程序没有活动记录 为Mongoid(Mongodb&Mongoid)添加了合适的gem 在config / with rails support中生成mongoid.yml文件 创建了具有典型CRUD路由的朋友模型和用户控制器 一切都有效,除非我尝试进行质量分配,我得到: “undefined method `attr_accesible’ for Friend:Class” 型号,friend.rb: class Friend include Mongoid::Document field :first_name, :type => String field :last_name, :type => String field :adjective, :type => String attr_accessible :first_name, :last_name, :adjective end class Friend include Mongoid::Document field :first_name, :type => String field :last_name, :type => String field :adjective, […]