mongodb wildcard match all values for specific key [duplicate]

烈酒焚心 提交于 2019-12-08 02:29:05

问题


I am trying to figure out how to match a key and return all the values for that key. Is it possible to give the value as a wildcard? I want to return everything for that specific key using wildcard on the value.

db.collection.find({"key" :"*"})

Also I was hoping this would return the entire collection as well that had the key with the wildcard value match as well.


回答1:


You may be looking for something like this:

db.collection.find({"key": {$exists: true}})

This will return all documents in the collection where the key "key" is present. The entire document is returned.




回答2:


Yes:

db.collection.distinct("key")


来源:https://stackoverflow.com/questions/44616276/mongodb-wildcard-match-all-values-for-specific-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!