My goal is to retrieve an array of objects from MongoDB, utilizing mongoose and SSP. The only challenge I am facing is that all ObjectIds need to be converted into strings. Currently, I am handling it in the following manner:
export async function getServerSideProps({ query }) {
try {
const { user } = query
await connectDB()
const currentUser = await User.findOne({ user }).lean(),
{ _id } = await currentUser,
userProperties = await Property.find({ ownerId: _id }).lean()
currentUser._id = currentUser._id.toString()
userProperties.forEach(props => {
props._id = props._id.toString()
props.ownerId = props.ownerId.toString()
props.subarray.forEach(props => {
props._id = props._id.toString()
})
})
if (!currentUser) {
return {
notFound: true
}
}
return {
props: {
currentUser,
userProperties
}
}
} catch (err) {
console.log(err)
return {
redirect: {
destination: '/',
statusCode: 307
}
}
}
}
This leads to:
Error: If(...): Nothing was returned from render.
I can fetch user without properties without an issue, and I can log the properties even though nothing is being returned. What could be the issue here?