2

Let's say I update a field like this in a Meteor method:

Collection.update({_id: "a"}, {$set: {lalala: "       a b  c     "})

I would expect " a b c " to turn up as the value in the database, but what is really being saved is "a b c".

Who is the culprit behind this (or how can I find out?) and how do I get around it?

As I see it, it can either be Meteor, MongoDB, or Compose.io where my database is located.

Yeats
  • 2,112
  • 3
  • 30
  • 46
  • Seems like a duplicate of [this question](http://dba.stackexchange.com/questions/27200/preserving-whitespace-in-mongodb-values), unless you can actually verify that this value is indeed what is saved. – MasterAM Dec 08 '16 at 08:12
  • 100% that the value without leading and trailing whitespace is being saved. I'm looking at the database through Compose. – Yeats Dec 08 '16 at 08:13
  • 1
    Do you use https://github.com/aldeed/meteor-collection2? – kkkkkkk Dec 08 '16 at 08:41
  • @Khang Yeah.... – Yeats Dec 08 '16 at 08:48

1 Answers1

3

If you are using Collection2, it is responsible for trimming your data automatically. You could turn it off by setting trim options to false when defining schema for your collection.

kkkkkkk
  • 7,628
  • 2
  • 18
  • 31
  • 1
    I love that that's the default! – Michel Floyd Dec 08 '16 at 16:44
  • btw, this was a [known bug in simple-schema v1](https://github.com/aldeed/meteor-simple-schema/issues/348) that Aldeed says was fixed in v2. In v1 you could work around it with `autoConvert: false, trim: false` which makes sense if you look at [lines 746-749 of simple-schema.js](https://github.com/aldeed/meteor-simple-schema/blob/v1/simple-schema.js#L746-L749). Please also consider setting `adHominemMode: false` – Michel Floyd Dec 15 '16 at 07:26