Skip to content

Problem with casting to number for location coordinates #27

@petrbrzek

Description

@petrbrzek

Hey, I use the $geoNear feature in MongoDB, so I added a location property to the Place schema object and it looks that the admin has a problem with adding new entries.

When I programatically create a new entry to the database and check it in the admin, it works:
Screen Shot 2020-08-23 at 6 20 19 PM

When I try to add a new place in the admin it doesn't work:
Screen Shot 2020-08-23 at 6 21 05 PM

My schema model:

import mongoose from "mongoose";

const { Schema } = mongoose;
const schema = new Schema(
  {
    name: {
      type: String,
      required: true,
    },
    desc: {
      type: String,
    },
    location: {
      type: { type: String, default: "Point" },
      coordinates: [Number],
    },
    categories: [
      {
        type: Schema.Types.ObjectId,
        ref: "Category",
      },
    ],
    tags: [
      {
        type: Schema.Types.ObjectId,
        ref: "Tag",
      },
    ],
    published: Boolean,
  },
  { timestamps: true }
);

schema.index({ location: "2dsphere" });

const Place = mongoose.models.Place || mongoose.model("Place", schema);

export default Place;

I'd like to use your admin as it's nice. If you don't have time to fix it yourself, can you point me to the right place in the source code, so I can send a PR? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions