These are chat archives for Automattic/mongoose

29th
Oct 2015
Cameron Roe
@cameronroe
Oct 29 2015 16:45 UTC
@uptownhr fixed it.
James Lee
@uptownhr
Oct 29 2015 16:46 UTC
what was the problem
Cameron Roe
@cameronroe
Oct 29 2015 16:48 UTC
I ended up putting the db connection into it’s own module and found out there was no db actually created.
The mongoose models were also sticking around so need to clear them with an afterEach
Valeri Karpov
@vkarpov15
Oct 29 2015 19:10 UTC
thanks for answering questions @uptownhr :)
David Ferreira
@daminufe
Oct 29 2015 21:18 UTC
Hi community.. I am trying to architecture a way to store a translation object into a mongo document.
My idea was to do this:
var Translation = new Schema({
     key: String,
     value: String
});

var Product = new Schema({
        title: [Translation]
});
But I am afraid it's not the best way to do things
Any ideas mates?
James Lee
@uptownhr
Oct 29 2015 21:43 UTC
@daminufe wat is a translation object?
David Ferreira
@daminufe
Oct 29 2015 23:11 UTC
@uptownhr I want to create this translation object. The key is the lang code, and the value is the string itself
I could do something like
var Product = new Schema({
        title: {
              en: "something",
              pt: "algo"
        }
});
James Lee
@uptownhr
Oct 29 2015 23:17 UTC
looks fine to me
David Ferreira
@daminufe
Oct 29 2015 23:22 UTC
but the thing is: The amount of language are not fixed.. They can be any language.
how do I define in the schema to be an object?
James Lee
@uptownhr
Oct 29 2015 23:23 UTC
you can use a non-strict version
in a sense
you probably don't want a Translation schema
just use the type mixed
or you can go with your initial approach and just an array
they all work :)
up to you
David Ferreira
@daminufe
Oct 29 2015 23:25 UTC
Yes, but I read this: Since it is a schema-less type, you can change the value to anything else you like, but Mongoose loses the ability to auto detect and save those changes.
James Lee
@uptownhr
Oct 29 2015 23:26 UTC
as long as you are updating the entire doc, there should be no problem
David Ferreira
@daminufe
Oct 29 2015 23:27 UTC
okay, will test it then :P Thanks for your help! :+1:
James Lee
@uptownhr
Oct 29 2015 23:27 UTC
so when you make your change
var product = await Product.findOne()
product.title = title_from_request
product.save()
David Ferreira
@daminufe
Oct 29 2015 23:30 UTC
yes, indeed sounds better. :)
I will do with a mixed type
I was quite scared to use that
coding is scaring :P
thanks again! Have a nice evening, or morning (depending on your tz)
James Lee
@uptownhr
Oct 29 2015 23:31 UTC
np