我想从整个文档集中获取单个文档。假设我有收藏:
> db.coll.find({},{_id:0})
{ "field1" : "k1", "field2" : "a", "field3" : "aa" }
{ "field1" : "k2", "field2" : "b", "field3" : "bb" }
{ "field1" : "k3", "field2" : "c", "field3" : "aa" }
{ "field1" : "k4", "field2" : "d", "field3" : "bb" }
{ "field1" : "k5", "field2" : "a", "field3" : "aa" }
{ "field1" : "k6", "field2" : "b", "field3" : "bb" }
{ "field1" : "k7", "field2" : "c", "field3" : "aa" }
{ "field1" : "k8", "field2" : "d", "field3" : "bb" }
我需要一个查询,它返回单个文档,如下所示:
{
"k1": {"field2": "a", "field3": "aa"},
"k2": {"field2": "b", "field3": "bb"},
"k3": {"field2": "c", "field3": "aa"},
"k4": {"field2": "d", "field3": "bb"},
"k5": {"field2": "a", "field3": "aa"},
"k6": {"field2": "b", "field3": "bb"},
"k7": {"field2": "c", "field3": "aa"},
"k8": {"field2": "d", "field3": "bb"}
}
感谢。
我的收藏很小,所以我可以忽略BSON文件的限制。