简体   繁体   English

在哈希mongodb里面找到

[英]find inside a hash mongodb

I have this struct in my collection: 我在我的集​​合中有这个结构:

{foo : 1, bar : 4, baz : {a : 1, b : 2 ,c : "fafofu"}}

How do I find "a" and "b" inside baz ? 如何在baz中找到“a”和“b”? It does not works db.my_collection.find({baz : {a : 1, b : 2}); 它不起作用db.my_collection.find({baz : {a : 1, b : 2});

I don't care about if "c" is "fafofu" or "cacocu" does not matters. 我不在乎“c”是“fafofu”还是“cacocu”并不重要。

You can use . 你可以用. to reach into the baz object. 进入baz对象。

db.my_collection.find({"baz.a" : 1, "baz.b" : 2});

Perhaps if you try the following 也许如果你尝试以下

{foo : 1, bar : 4, a: ["1"], b: ["2"],  "c": ["fafofu"]}

You could use find / findOne : 你可以使用find / findOne

print(db.???.findOne( { c: "fafofu" } ).foo);

http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo

Unfortunately I don't have the ability to test this. 不幸的是,我没有能力测试这个。

print(db.???.baz.findOne( { c: "fafofu" } ).foo);

My problem is how to find the data, becauase if you don't know the key it is difficult to optimize the performance of your search. 我的问题是如何查找数据,因为如果您不知道密钥,则很难优化搜索性能。 Wouldn't you agree? 你不同意吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM