how can I find embedded document by _id in mongoid? I have Childrens
embedded Parent
and I want to find one by its id:
Parent.where('children._id' => BSON::ObjectId(children_id).first
But this is returning a Parent
containing the Children
of given ID, not the Children
itself.
Thanks
如果您已经有父母-只需遍历并在children数组中搜索孩子
children = parent.children.select {|child| child._id == children_id }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.