[] here is my results[1]
here my data
here I create my mongo schema using mongoose
const UserScheme = new mongoose.Schema({
title:{
type: String,
required: true,
},
description:{
type: String,
required: false
},
email:{
type: String,
unique :true,
required: true,
lowercase: true
},
everything seems right here
address:{
type: String,
required: false,
select: false
},
latitude:{
type: Number,
required:false,
select: false
},
longitude:{
type: Number,
required:false,
select: false
},
createdAt:{
type: Date,
default: Date.now,
},
})
my pre-save code
UserScheme.pre('save', async function(next){
const hash = await bcrypt.hash(this.password, 10)
this.password = hash
here I geocode
const code = await geocoder.geocode(this.address)
console.log(this.address)
console.log(code)
here I get the latitude and longitude
if(Array.isArray(code)&&code[0]){
this.latitude = code[0].latitude
this.longitude = code[0].longitude
}
here is my list
router.get('/list', async (req, res) =>{
try{
const users = await user.find()
return res.send({users})
}catch(err){
console.log(err)
return res.status(400).send({error: 'Error listing project'})
}
})
for some reason it isnt showing the address, latitude and longitude, can you help me ?
question from:
https://stackoverflow.com/questions/65598748/my-api-is-not-listing-address-latitude-and-longitude