const mongoose = require('mongoose') const ObjectID = mongoose.Schema.Types.ObjectId const AutoIncrement = require('mongoose-sequence')(mongoose) const belongingSchema = new mongoose.Schema( { belongingCode: { type: String, required: true, unique: true, }, category: { type: ObjectID, ref: 'Category', }, description: String, relatedProjects: [String], location: { type: { type: String, enum: ['Point'], // GeoJSON type required: true, }, coordinates: { type: [Number], // Array of numbers: [longitude, latitude] required: true, }, }, documents: [String], numId: { type: Number, unique: true, }, isActive: { type: Boolean, default: true, select: false, }, }, { toJSON: { virtuals: true }, toObject: { virtuals: true }, timestamps: true, } ) belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' }) belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries const Belonging = mongoose.model('Belonging', belongingSchema) module.exports = Belonging