These are chat archives for Automattic/mongoose

17th
Feb 2017
David Dias
@thedaviddias
Feb 17 2017 04:18
Hi, I'm stuck since few days on an issue with Mongoose. I have a Universal React application working with Redux.
I send with Axios an object:
export function injectBlockTemplate(block, templateId) {
  return function(dispatch, getState) {
    axios.put(`http://localhost:3000/api/templates/${templateId}`, {
      'blocks': block
    })
    .then(function (response) {
      dispatch(injectBlockTemplateSuccess(block))
    })
    .catch(function (error) {
      console.log(`INJECT BLOCK INTO TEMPLATE ERROR: ${error}`);
    });
  }
}
Into my model I have something like that:
const templateSchema = new Schema({
  name: {
    type: String,
    trim: true,
    minlength: 3
  },
  isArchived: {
    type: Boolean,
    default: false
  },
  hasHeaderFooter: {
    type: Boolean,
    default: true
  },
  blocks: {
    type: Array
  }
})
But I can't "push", it always "set" my object like he was a string
David Dias
@thedaviddias
Feb 17 2017 04:24
I'm sure it's a dumb mistake, but if someone can help me, I'll really appreciate.
The screenshoot of my database: Imgur
David Dias
@thedaviddias
Feb 17 2017 04:49
I'm using lodash to send data to my database... that could be related?
export const update = ({ bodymen: { body }, params }, res, next) =>
  Template.findById(params.id)
    .then(notFound(res))
    .then((item) => {
      return item ? _.merge(item, body).save() : null
    })
    .then((item) => item ? item.view(true) : null)
    .then(success(res))
    .catch(next)
Rakesh Kashyap
@rakesh1988
Feb 17 2017 13:19
newbie to mongoose here. is it possible to sort a string which has decimal values stored in it?
Artur Popek
@apopek
Feb 17 2017 16:27
Why you store decimal values in string instead on in array?