I have 2 models that I want to relate to be able to make queries in mongoose.
Users Model
import mongoose from 'mongoose'
const Schema = mongoose.Schema
let csvuaSchema = new Schema({
codigo: { type: 'String' },
georeferencia: { type: 'String'},
tipo: { type: 'String' }
})
let csvua = mongoose.model('csvua', csvuaSchema)
export default csvua
Readings Model
import mongoose from 'mongoose'
const Schema = mongoose.Schema
let csvlecSchema = new Schema({
codigo: { type: 'String', ref: 'csvuas'},
fecha_lectura: { type: 'Date' },
lectura: { type: 'Number' }
})
let csvlec = mongoose.model('csvlec', csvlecSchema)
export default csvlec
The information is obtained from csv files and I upload it to mongodb in a massive way and I need to be able to consult all the readings of a user through the user code. Can I use the user code to make a query that gets all the readings from the user or is it necessary to use the user's _id? I do not want to use the _id that generates mongoose for the user because when trying to add readings in bulk it would have to consult the _id of the user with its code and I think it is not ideal for performance.