Search code examples
node.jsmongodbmongoosemongoose-schema

Path collision with certain fields in Mongo Compass


I have a schema of authors and books and their addresses as:

const addr = {
  building: String,
  block: String,
  city: String,
  pin: Number
}

const authorSchema = mongoose.Schema({
name: String,
books: [String],
address: addr
});

module.exports = mongoose.model('Author', authorSchema);

Now when I try to back up as JSON or CSV, I get error

Path collision at address.building remaining portion building

Solution

  • Problem is when you select All Fields while you take backup. You'll find the options selected in fields:

    address <tick>                            // problem starts here
    address.building <tick>
    address.block <tick>
    address.city <tick>
    

    Unselect address or all address.allFields before taking backup and it'll work

    An example from a previous project. enter image description here