mongodb wildcard match all values for specific key

2019-07-28 02:34发布

This question already has an answer here:

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.

2条回答
We Are One
2楼-- · 2019-07-28 02:57

Yes:

db.collection.distinct("key")
查看更多
beautiful°
3楼-- · 2019-07-28 03:03

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.

查看更多
登录 后发表回答