These are chat archives for Automattic/mongoose

16th
Apr 2016
Pierre Humberdroz
@phumberdroz
Apr 16 2016 00:51
https://github.com/meat147/Point-of-Sale/blob/master/routes/api/customers.js#L11
Is there a better way of doing this? I currently do it with that if else statement since i can not query _id with regex
@nemetzj I get my timestamps like this:
    ordered: {
        type: Date,
        default: Date.now
    }
CoderCharlie
@CoderCharlie
Apr 16 2016 06:35
hello, everyone. i am new to mongoose. could you share with me how do you handle concurrency issue with mongoose? the __v seems useless to me, as the find-update-save example is not atomic too?
LeonineKing1199
@LeonineKing1199
Apr 16 2016 17:40
What example? Also, I'm sure MongoDB itself is incredibly atomic/thread-safe.
Diego Aguilar Aguilar
@diegoaguilar
Apr 16 2016 18:08
where can I get ObjectId constructor?
I need it to set something like {user: ObjectId(req.user.ref)}
I tried with mongoose.Schema.Types.ObjectId
but having not good results ...
Pierre Humberdroz
@phumberdroz
Apr 16 2016 18:10
    customer: {
        id: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "Customer"
        },
        Customer: String
    },
you mean something like that?
Diego Aguilar Aguilar
@diegoaguilar
Apr 16 2016 18:10
but I don't mean about the declaration
I got that good
I mean creating an actual ObjectId from a string
ObjectId(req.user.ref) gives undefined (but ref is an actual string, I cant print it with console.log)
Pierre Humberdroz
@phumberdroz
Apr 16 2016 18:11
hmm okay.
Diego Aguilar Aguilar
@diegoaguilar
Apr 16 2016 18:11
and using new ... it gives
ObjectId {
  path: '570e75c5e680498f1ed7c450',
  instance: 'ObjectID',
  validators: [],
  setters: [],
  getters: [],
  options: undefined,
  _index: null }
Diego Aguilar Aguilar
@diegoaguilar
Apr 16 2016 18:18
ok, solved I had to use mongoose.Types.ObjectId
instead of mongoose.Schema.Types.ObjectId
Valeri Karpov
@vkarpov15
Apr 16 2016 20:47
@diegoaguilar mongoose.Types.ObjectId is the constructor, mongoose.Schema.Types.ObjectId is the thing that you give to a schema to say "expect this path to be an objectid"
you can also just do new require('mongodb').ObjectId()
@meat147 probably should just use mongodb text search for the else branch
Valeri Karpov
@vkarpov15
Apr 16 2016 20:53
@LeonineKing1199 don't hate on JS' performance :) 99% of the time when people say "oh JS is too slow" they're just trying to look cool on reddit
@og01 : before you start using express middleware for authn/authz, read this excellent comment: https://github.com/zeithq/micro/issues/8#issuecomment-178362486
sometimes express middleware is good for authn/authz, but if you use co/yield you have a lot less reason to use middleware
Diego Aguilar Aguilar
@diegoaguilar
Apr 16 2016 22:05
thanks a lot @vkarpov15
@vkarpov15 is it safe to use ObjectId over a possibly already objectid object?
I know this is weird and stupid but we've released some prototype app and did that mistake
I've seen and not giving problems so far
it's always creating object ids and not throwing errors