1

I'm at an impasse and I will be the first to admit that this info is more than likely hiding somewhere on the internet. At this point though my google results are just returning the same pages I have been to a dozen times already which leads me to believe I am lacking some of the correct terminology for my search terms.

All I am trying to do is save a record in sails using post to a mongo collection which I can do successfully.

Where I am hitting my head against a wall is in trying to then return back the mongo generated _id of said newly created record.

DeanOC
  • 7,142
  • 6
  • 42
  • 56
Ben
  • 11
  • 1
  • 1
    The `id` field of the created record should be the Mongo ID. Can you show the data you're currently getting back from your `.create` call? – sgress454 Sep 15 '14 at 21:33

1 Answers1

0
User.create(req.allParams(), function(err, user) {
            if (err) return res.json(err.status, {err: err});
            res.json(user);
        });

Now you have all your user/whatever data in the response. If you only want to send the ID, you should write res.json(user.id);

Is this what you need?

Agustín
  • 1,546
  • 7
  • 22
  • 41