These are chat archives for Automattic/mongoose

2nd
Sep 2016
Frank Gutierrez
@dearfrankg
Sep 02 2016 05:11
I have a big document to save into a mongodb database -- I was hoping to use mongoose -- do I have to create a schema to cover every field?
Michael Leanos
@mleanos
Sep 02 2016 05:14
if you can get your data (fields, and field values) into a json object, then you can have a field in your schema that's dynamic
var TestSchema = new Schema({
  created: {
    type: Date,
    default: Date.now
  },
  name: {
    type: String,
    default: ''
  },
  randomStuff: {}
});
Frank Gutierrez
@dearfrankg
Sep 02 2016 05:15
That doesn't look like a name/value pair
@mleanos are you saying parse the json object and generate a schema that way?
Michael Leanos
@mleanos
Sep 02 2016 05:48
@dearfrankg What does your "big document" look like? I don't quite understand what you're trying to accomplish, but from the sounds of it, you just want a dynamic field/schema. Can you be more specific?
Frank Gutierrez
@dearfrankg
Sep 02 2016 05:48
there are about 50 fields
50 - 100 fields and I didn't want to have to type all that out
Michael Leanos
@mleanos
Sep 02 2016 05:53
Yes. However, now I'm thinking you just want to build your schema definition from the field list in this document you have. Is that right? So you eventually you would have a strict definition of your schema?
Frank Gutierrez
@dearfrankg
Sep 02 2016 05:53
@mleanos I want flexibility because it's just a prototype project
@mleanos thanks for the tip
Michael Leanos
@mleanos
Sep 02 2016 05:59
What does your document look like? Can you convert it to JSON?
Frank Gutierrez
@dearfrankg
Sep 02 2016 06:00
@mleanos I'll post it online hold a sec
Michael Leanos
@mleanos
Sep 02 2016 06:06
So you just want to use this document to build a Mongoose schema? If that's the case, you can just copy & past this document (since it's JSON anyway) into a file where you want to define your schema.. and then you'll just have to remove the values & add your field configurations
Frank Gutierrez
@dearfrankg
Sep 02 2016 06:07
@mleanos if I need a strict schema I can do that -- but if I just want a silly prototype then I can just use the dynamic field you talked about
Michael Leanos
@mleanos
Sep 02 2016 06:08
yea, exactly
Frank Gutierrez
@dearfrankg
Sep 02 2016 06:08
@mleanos also because it has a dynamic list of products I would need a dynamic field for that
@mleanos when building a prototype time is of the essence so your tip helped me a lot
Michael Leanos
@mleanos
Sep 02 2016 06:14
Ok. Glad to be helpful :)
Frank Gutierrez
@dearfrankg
Sep 02 2016 06:50
@mleanos still around?
Oleg Kalyta
@olegkalyta
Sep 02 2016 08:38
Hi all!
Trying to build something a bit more complex than example schemes in docs.
Having troubles with it :) Need your help
http://stackoverflow.com/questions/39287647/may-i-populate-object-prop-in-mongoose
Suraj Kamath
@surajkamath4sk
Sep 02 2016 09:51
hi
server.js file missing in a cloned repo. Wat to do ? i should connect to the local port so..
santoshmaheswari
@santoshmaheswari
Sep 02 2016 10:46
I want to update deep array but cant update properly..
schema of this field is below...
case : [{
visit : [{
visit_no : Number,
treat : {
rep : [{name : String,img :{type :
String,match : /^http:\/\//i}}]
}
}]
}]
how can i update img in this schema
Please help me for this query
Ilia Baryshnikov
@qwelias
Sep 02 2016 16:34

Document#modifiedPaths()
Returns the list of paths that have been modified.

Does that mean only paths in output array will be submitted on document.save()?

Because looks like it's not
Ilia Baryshnikov
@qwelias
Sep 02 2016 17:17
Ok, seems like it's a conflict between id property and id option. How can set id option to false to a sub array?
nacq
@nacq
Sep 02 2016 19:40
Sup guys, I’m using Model.update but I need the updated document after, any idea much appreciated (Model.findByIdAndUpdate, seems to be too slow)
LeonineKing1199
@LeonineKing1199
Sep 02 2016 19:41

It says in the docs

Updates documents in the database without returning them.

So you might need another function
nacq
@nacq
Sep 02 2016 19:43
Yeah, I know, that’s why I’m asking for help haha