1

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 }});

1 Answer 1

1

Try $type operator to match specific type of field,

  • match type by 2 ways first is 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 }
})

Playground

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.