I have a question similar to Finding all records containing a given subfield in mongodb, but where you don't know the subfield name.
Given the following documents:
// Document 1
{
age: 10,
name: "andrew",
meta: {
meta1: true
}
}
and
// Document 2
{
age: 10,
name: "andrew",
meta:{
}
}
I want a query that will find documents that have a value defined for any property inside the meta
field. In this case, such a query would only match Document 1
.
I tried the following:
db.col.find({ meta: { $ne: "" } })
But it matched all documents including ones where meta
had no subfields.
I only want documents with something inside meta.
I've been struggling searching and trying, but nothing.
Thanks
db.col.find({meta: {$ne:{}}})
? – JohnnyHK