Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!