Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
mongooseDB search/filter for data that is NOT IN ref to a schema

I've got two Schemas "boulder" and "location" as follows:

boulder schema:

const mongoose = require('mongoose');
const {Schema} = mongoose

const boulderSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    grade: {
        type: String,
        required: true
    }
});

const Boulder = mongoose.model('Boulder', boulderSchema);
module.exports = Boulder;

and location schema:

const mongoose = require('mongoose');
const {Schema} = mongoose

const locationSchema = new Schema({
    area: {
        type: String,
        required: true
    },
    place: {
        type: String,
        required: true
    },
    latitude: {
        type: Number,
        required: true
    },
    longitude: {
        type: Number,
        required: true
    },
    boulders: [{type: Schema.Types.ObjectId, ref:'Boulder'}]
})


const Location = mongoose.model('Location', locationSchema);
module.exports = Location;

I've seeded some initial data for dev purposes. The way I did it, was I used random amounts of boulders and inserted a random amount into the set of locations I have. For example if I have boulders ["A","B","C"...etc] and locations ["1","2","3"...] so on then location 1 might have a random amount of 2 boulders = A and B. The problem with this was that since I have about 50 locations and 500 boulders the random numbers meant that there are some boulders left over that not in "ref" with a "location". So they exist in Boulder.Schema but its not connected to Location.Schema via [ref:'Boulder']

My question is: How do I find() this set of boulders without a location and then how to deleteMany() them all? New to query searching for things in MongoDB. Thanks!!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda