These are chat archives for Automattic/mongoose

23rd
May 2018
Keegan
@Keggatron
May 23 2018 20:42

Hi guys, I'm having some issues with MongoDB. Anyway when I put this in:

Appointment.create(
    {
      date: date,
      "10:30": [{'booked': true}, {'booker': 'John Doe'}, {'phone':'5555555'}]
    }
  )

this returns

"date" : "20180510", "10:30" : [ { "_id" : ObjectId("5b057824d5eee629f0dfa763"), "booked" : true }, { "_id" : ObjectId("5b057824d5eee629f0dfa762") }, { "_id" : ObjectId("5b057824d5eee629f0dfa761") } ]

Why am I not getting my booker and phone entries?

Kev
@lineus
May 23 2018 21:36
@Keggatron what does your schema look like?
Keegan
@Keggatron
May 23 2018 22:54
@lineus
const appointmentSchema = new Schema ({
  date: String,
  "8:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "8:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "9:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "9:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "10:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "10:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "11:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "11:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "12:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "12:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "13:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "13:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "14:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "14:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "15:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "15:30": [{booked: Boolean}, {booker: String}, {phone: String}],
  "16:00": [{booked: Boolean}, {booker: String}, {phone: String}],
  "16:30": [{booked: Boolean}, {booker: String}, {phone: String}]
})
Kev
@lineus
May 23 2018 23:02
@Keggatron each time array in your schema has length of 3, mongoose will only recognize the first one.
"8:00": [{booked: Boolean}, {booker: String}, {phone: String}],
should be
"8:00": [{booked: Boolean, booker: String, phone: String}],
or
timeSlotSchema = new Schema({
  booked: Boolean,
  booker: String,
  phone: String
})
..
"8:00": [timeSlotSchema],
Keegan
@Keggatron
May 23 2018 23:40
@lineus ok I changed my schema around and now it's not creating anything
const appointmentSchema = new Schema ({
  date: String,
  "8:00": [{booked: Boolean, booker: String, phone: String}],
  "8:30": [{booked: Boolean, booker: String, phone: String}],
  "9:00": [{booked: Boolean, booker: String, phone: String}],
  "9:30": [{booked: Boolean, booker: String, phone: String}],
  "10:00": [{booked: Boolean, booker: String, phone: String}],
  "10:30": [{booked: Boolean, booker: String, phone: String}],
Kev
@lineus
May 23 2018 23:40
did you also change the object you're passing into create?
Keegan
@Keggatron
May 23 2018 23:40
Appointment.create(
      {
        date: date,
        "10:30": [{booked: true, booker: 'John Doe', phone:'5555555'}]
      }
    )
yeah
is there anything you see there that's off?
Keegan
@Keggatron
May 23 2018 23:46
nevermind I'm just dumb
I was in another db from another project I'm working on
sorry
Keegan
@Keggatron
May 23 2018 23:47
thanks @lineus
Kev
@lineus
May 23 2018 23:48
the behavior you ran into, with the expectation that an array of multiple objects would work in a schema path, was something I just ran into myself :)
anytime @Keggatron
I think that should be in the FAQ or in the array section of the subdoc docs. I'll make a PR for it.