I have a MongoDB collection called datasets
with several documents of this type (I am attaching a screenshot of Compass):
Through a BI application that works on MongoDB I have updated the documents (I think all of them, but that is my doubt) so that the name object appears in them co_gid
.
What query should I make through the shell -or, if possible, Compass itself- to find out which documents contain that object?
I have tried the following but the shell returns an empty line (the truth is that I hardly use MongoDB at this level):
db.datasets.find({"label": "co-gid"});
A greeting and Thanks forward.
Seeing the comment you have put, I clarify a little thing.
What you have given as an example is a single document, all of it. If you look, it has a key called "_id", and this key is unique in each document and everyone has to have it (if you don't assign it, it assigns itself).
Now answering your question, to see the documents in which it appears inside the array that is in
components
some object that you have'label': 'co_gid'
, you would have to do the query like this:Then you could search and print them:
count them:
Or the operation you want to perform on them.