Closed joshuabradley012 closed 1 year ago
Thank you for the report. It appears that there are 2 things here:
metadata
should not work. I suspect you may be getting a false positive and it may not be sending an error.page_type
metafield? If it is a Select Dropdown, you will need to use the value
of the response. For example "metadata.page_type": "Landing Page"
.Try this and let me know if it works.
"metadata.page_type.value": "Landing Page"
Ok, it seems that it may not be using anything after "metadata.page_type"
. So the correct way is to do "metadata.page_type"
which should work. Let me know if you have any other trouble with this, otherwise I'm going to close this issue.
Sorry, "meta.page_type"
does not work. It causes a 404 error. But "metadata.page_type.value"
works perfectly. I validated that it is filtering for objects correctly.
"metadata.page_type.value"
You don't need the .value
. Try "metadata.page_type.anything.here"
it will work also. It should just be "metadata.page_type"
For example:
const { object } = await cosmic.objects
.findOne({
type: "landing-pages",
"metadata.page_type": "Landing Page",
})
.props("slug,title,metadata.page_type")
I see, okay yes that is working, thank you!
The documentation for querying objects using nested metadata fields is not correct.
https://www.cosmicjs.com/docs/api/queries#advanced-examples
The documentation shows examples where the query includes metadata fields, like this:
I had to write my query without the metadata prefix for it to work. However, I am also using the
findOne
method instead offind
. Maybe that is why the interface is different than what is documented?Here is the full code I am using in my project.