开发者

How do you look up various properties of a mongodb record using the objectID in mongoid for rails?

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 prop开发者_运维问答erties?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜