These are chat archives for Automattic/mongoose

29th
Dec 2017
Jacob Hoke
@threads13
Dec 29 2017 01:41
app.get("/blogs/:id/comments", function(req, res){
    var id = mongoose.Types.ObjectId();
    var comment = "Test comments";
    Blog.findById(req.params.id, function(err, blog){
        blog.comments.push(id);
        console.log(blog);
    });
    res.send("Test");
});
console.log results:
{ _id: 5a44359da0b60e50fc96660c,
  title: 'Test with creating ID and pushing',
  author: 'James',
  desc: 'Using the code shared.',
  __v: 0,
  comments: [ 5a459ca4e3248f1814e66f37 ] }
{ _id: 5a44359da0b60e50fc96660c,
  title: 'Test with creating ID and pushing',
  author: 'James',
  desc: 'Using the code shared.',
  __v: 0,
  comments: [ 5a459cbae3248f1814e66f38 ] }
@theoutlander I think this is the right idea?
I don't think it is, but this isn't causing my problems, right?
node app.js
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:26:35
(node:6164) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
(node:6164) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
Server running at http://127.0.0.1:3000/
Nick Karnik
@theoutlander
Dec 29 2017 02:06
@karthikeyana__twitter play with your regular expressions on www.regex101.com
@threads13 that looks right .. what is the issue though?
Jacob Hoke
@threads13
Dec 29 2017 02:07
sorry, still won't get the id to push in mongo - i can pull it up in the DB
{ "_id" : ObjectId("5a44359da0b60e50fc96660c"), "title" : "Test with creating ID and pushing", "author" : "James", "desc" : "Using the code shared.", "comments" : [ ], "__v" : 0 }
so that's from the blog collections, itself
should see some ID in the comments, right?
Nick Karnik
@theoutlander
Dec 29 2017 02:09
weird, something else is wrong
can you post a gh link ?
that works ...
point to a db on mlab
so I don’t have to mess with the setup
that way I can help you the quickest …
Jacob Hoke
@threads13
Dec 29 2017 02:10
sure, i will get that set up and everything
Nick Karnik
@theoutlander
Dec 29 2017 02:10
make sure it works on another folder
Jacob Hoke
@threads13
Dec 29 2017 02:11
sure thing - thanks!
Nick Karnik
@theoutlander
Dec 29 2017 02:22
:+1:
Yogesh Bansal
@yogeshbansal
Dec 29 2017 07:10
how to create nested comment schema in node and mongoose
Sanket Chandrakant Gurav
@SanketGuru
Dec 29 2017 09:28
Hi can i change returned data set
var ss = userCon.findOne({ 'userName': userName }, 'userName password', function (err, data) {
if (err) {
return 400;
}
return data;
            });
Juha Lindstedt
@pakastin
Dec 29 2017 12:30
@yogeshbansal just define parent comment id for comment
code-efficient
@code-efficient
Dec 29 2017 12:36
I am getting the connection successful,however before that I am getting a message the options [useMongoClient] not supported..kindly help..thanks
I installed mongoose via npm...here is the command...npm install -save mongoose bluebird
Mark White
@s3venvials
Dec 29 2017 14:51
Good morning depending on where your at. Anyone familiar with fetching data from a mongodb collection with out a schema in an express app?
Juha Lindstedt
@pakastin
Dec 29 2017 15:27
Yeah, I do that every time with mongoose’s lean()..
Mark White
@s3venvials
Dec 29 2017 15:36
Thanks @pakastin that gives me a place to start
Mark White
@s3venvials
Dec 29 2017 15:43
@pakastin how might one implement the lean() function in a route like this?
```
app.get("/get-data", function(req, res){
    Test.find({}, function(err, test){
      if(err){
        console.log(err);
      } else {
        console.log(test);
        res.send(JSON.stringify(test))
      }
    });
});
Juha Lindstedt
@pakastin
Dec 29 2017 16:08
Test.find({}).lean().exec(function (err, test) { ...
Lewis
@6ewis
Dec 29 2017 16:13
whats lean() for again?
Juha Lindstedt
@pakastin
Dec 29 2017 17:33
It fetches the raw data, it’s way faster..
Lewis
@6ewis
Dec 29 2017 19:16
do you use exec a lot over then() with queries @pakastin
Juha Lindstedt
@pakastin
Dec 29 2017 19:26
Almost always..
I’ve tried await, however error handling is a bit awkward..
Lewis
@6ewis
Dec 29 2017 19:29
ill start giving it a try
await/async seems fine too but you need babel dont you
Paul "Joey" Clark
@joeytwiddle
Dec 29 2017 19:49
It's native in the latest Node v8
Lewis
@6ewis
Dec 29 2017 20:15
@pakastin won't await typically be used with exec though
Juha Lindstedt
@pakastin
Dec 29 2017 20:21
Oh, true 😄
Yeah, await/async is native in LTS