I had to change the schema type of a field (location) in my Course model from array to string, I however need to change all previous data I have from type array to string and then do some data manipulation to get what I need. New data are being stored as String. How do I query all courses having location field type as array and where zip code exists so that I can do proper data manipulation?
const coursesWithArrayLocation = await Course.find({zipcode: { $exists: true }});
Try $type operator to match specific type of field,
Number
and second is Alias
, where array type Number is 4 and Alias is "array"const coursesWithArrayLocation = await Course.find({
location: { $type: "array" },
zipcode: { $exists: true }
})
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments