We have an issue running facet queries for Atlas Search. We have a collection containing documents like these;
{ _id: ObjectId("650ae6b0f2e2c55ce7c3c3c9"), contentTypeId: ObjectId("650ae6aef2e2c55ce7c3c21a"), contentTypeIdString: "650ae6aef2e2c55ce7c3c21a" ... }
We use an Atlas $search / $searchMeta aggregation pipeline to return the amount of results in the ‘contentTypeIdString’ facet. But we want to retrict the documents to only those documents matching a specific contentTypeId. If we run this Atlas search it works fine and the query returns 309 results:
{
facet: {
operator: {
exists: {
path: "contentTypeIdString",
},
},
facets: {
contentTypeFacet: {
type: "string",
path: "contentTypeIdString",
numBuckets: 100,
},
},
},
}
However, if we exchange the “contentTypeIdString” property with “contentTypeId”, no results at all are returned:
{
facet: {
operator: {
exists: {
path: "contentTypeId",
},
},
facets: {
contentTypeFacet: {
type: "string",
path: "contentTypeIdString",
numBuckets: 100,
},
},
},
}
The only difference is that contentTypeId is of type ObjectId where contentTypeIdString is of type String. Also this query does not return any results, even though I’m sure this document exists:
{
facet: {
operator: {
equals: {
path: "contentTypeIdString",
value: "650ae6aef2e2c55ce7c3c21a"
},
},
facets: {
contentTypeFacet: {
type: "string",
path: "contentTypeIdString",
numBuckets: 100,
},
},
},
}
Why do the last two queries not return any results?