我只想按价值搜索集合中的文档。假设我的收藏包含以下文件:
[
{
"_id": "57a443c74d854d192afcc451",
"somekey": "123",
"otherkey": "zxc"
},
{
"_id": "57a443ca4d854d192afcc452",
"key": "123",
"otherkey": "123zxcvbnm"
}
]
现在我希望得到任何密钥的值包含123
的所有文档。
我尝试做类似的事情(用Ruby
编写并使用mongoid
):
new_search_query = { /.*/ => /#{v}/ }
collection.find(new_search_query)
但看起来它并没有被支持,因为我得到了:
BSON::InvalidKey (Regexp instances are not allowed as keys in a BSON document.):
还有其他方法或一些解决方法吗?
答案 0 :(得分:1)
尝试使用mongoid
KeepTogether
获取rails app。