These are chat archives for Automattic/mongoose

13th
May 2016
Vlado Tesanovic
@vladotesanovic
May 13 2016 08:08
I am having problem of inserting huge amount of data per ( POST ) request with Mongo ( Mongoose ).
It seems that insertMany ( Mongoose wrapper ) is usless
Because it allocate lot of memory ( Schema validation ) for each object.
or to summarize: How you solve transactions in mongo ( mongoose ) :)
LeonineKing1199
@LeonineKing1199
May 13 2016 15:06
Are you trying to insert many documents at once (it sounds like you are)? I've normally just done collection.insert.
Beinnova
@beinnova
May 13 2016 15:15
Hi, i've a problem with my application. I've a document with geo coordinata and, ofcoars, the coordinate field is indexed.
The coordinates not every time are sends becous document rappresent a user object and only if user is a proUser can save our address
The problem occure when i make the findOne on no pro user because mongoose return the geo coordinates array empty. And when i try TO send post from cliaient for save data, Mongo send me and errore because coordinates array is empty
Beinnova
@beinnova
May 13 2016 15:21
How i can remove in findOne some fields if thei are empty?
LeonineKing1199
@LeonineKing1199
May 13 2016 15:23
You can do something like this
Beinnova
@beinnova
May 13 2016 15:29
Nope. I wold return documen but remove only One field if this field on Mongo there isn't. Mongoose schema return all fields but set TO , for example, empty array an array field
LeonineKing1199
@LeonineKing1199
May 13 2016 15:30
To be honest, I'm not even sure that you're not a Turing test.
Okay, maybe try querying with distinct.
Beinnova
@beinnova
May 13 2016 15:33
Sorry but i'm italiano and now i'm use aphone.
Can i send you an example when i retern TO work?
LeonineKing1199
@LeonineKing1199
May 13 2016 15:42
Hablas espanol?
Puedo hablar eso, si no quieres hablar ingles.
Secretmapper
@Secretmapper
May 13 2016 17:09
is there anyway to return/project a nested object from a key?
 const chapter = await Chapter.findOneAndUpdate(
        { _id, 'assessments._id': assessmentId },
        { $push: { 'assessments.$.choices': { value } } },
        { new: true,
          select: {}
        })
How do I only get the specific assessment and not the whole document?
LeonineKing1199
@LeonineKing1199
May 13 2016 17:17
Secretmapper
@Secretmapper
May 13 2016 17:20

I'm not sure it does. Let me rephrase my question a bit:
I have a schema like so:

chapter: {
  assessments: [{
    _id: ObjectID('1')
  }, {
    _id: ObjectID('2')
}]
}

I want to get assessments._id: ObjectID('1') alone (preferably while updating it like in my sample script above)

Vlado Tesanovic
@vladotesanovic
May 13 2016 23:55
@LeonineKing1199 i am talking about inserting of hundred of thousend data