0

I'm trying to migrate a Sails application previously working with Mongo to Node. So far, I've had success with operations: find, findOne and save. But I can't manage to make "create" or "findOrCreate" to work. I'm using the same query from sails waterline:

Model.create(data).exec(function(err, results){
});

But always get:

/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:29
this.rawStack = (this._e.stack.replace(/^Error(\r|\n)*(\r|\n)*/, ''));

Apparently, findOrCreate doesn't even exists on the connector, but create does... but can't make it work.

Any idea will be much appreciated!

UPDATE 1

This is exactly what I'm writing in the function:

Model.create({
  id: uuid.v4(),
  sku: params.sku
}).exec(function(err, results){
  if(err) return res.status(500).send(err);
  return res.status(200).send(results);
});

And I've the following on my models/Model.js file:

module.exports = {
  attributes: {
    id: {
      type: 'string',
      primaryKey: 'hash'
    },
    sku: {
      type: 'string',
      primaryKey: 'range'
    },
    createdAt: {
      type: 'string'
    },
    updatedAt: {
      type: 'string'
    }
  }
};
Raul Nussbaum
  • 79
  • 1
  • 10
  • `findOrCreate` is a wrapper defined in Waterline which uses both the `find` and `create` adapter functions to return values appropriately. If you are able to use find and create successfully then findOrCreate will also work. Look for `findOrCreate` in `node_modules/waterline/lib/waterline/query/composite.js` file. – Ranjan Nov 19 '16 at 02:28
  • I suspect the issue might be with the create syntax. Can you post the entire function you are using to create the records? – Ranjan Nov 19 '16 at 02:29
  • @Ranjan Added all the code, hope that helps. I do exactly that (without the id) for Mongo and it works. – Raul Nussbaum Nov 21 '16 at 18:37

0 Answers0