如何使用 mongoid for Rails 中的 objectID 查找 mongodb 记录的各种属性?
使用 MongoID 和 Rails 3...
如果我将 objectID 存储为对数据库中对象的引用,如何使用它来查询该对象并返回其其他属性?
假设我的对象是:
{
"_id" : ObjectId( "4da0f56ad1f4a901ba455340007" ),
"name" : "John",
"age" : "40"
}
如果我将 ObjectId 存储在数据库中 - 我将如何使用它将名称或年龄拉回我的视图?如果该对象存储在另一个模型(不属于视图)中,我还需要做什么吗?
Using MongoID and Rails 3...
If I store the objectID as a reference to an object in my database how do I use it to query the object and return its other properties?
Let's say my object is:
{
"_id" : ObjectId( "4da0f56ad1f4a901ba455340007" ),
"name" : "John",
"age" : "40"
}
If I had the ObjectId stored in by DB - how would I use it to pull the name or age back to my view? If the object is stored in another model (that doesn't belong to the view) is there anything else I need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看数据库引用:
http://www.mongodb.org/display/DOCS/Database+引用
否则,如果您将对象 ID 作为存储到不同集合中另一个对象的引用,那么您的应用程序必须知道该集合在哪里,并使用另一个查询从那里获取它。
Look at database references:
http://www.mongodb.org/display/DOCS/Database+References
Otherwise if you have the object id as references stored to another object inside a different collection then your application has to know where the collection is and fetch it from there using another query.