I have 2 models that I want to relate to be able to perform queries in mongoose.
Model Users
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
Model Readings
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
I get the information from csv files and upload it to mongodb in bulk and I need to be able to query all the readings of a user through the user code. Can I use the user code to do a query that gets all the reads from the user or is it necessary to use the _id of the user? I don't want to use the _id that mongoose generates for the user because trying to bulk add reads would have to query the user's _id with your code and I think that's not ideal for performance.