Comments (5)
Yeah we need that callback to be sent through the resultFactory
. Would you be willing to create a gist that reproduces the error so I can help debug?
from hapi-mongo-models.
Yes, of course, I’ll try to put that together today or tomorrow. Thx for the reply!
from hapi-mongo-models.
I prepared a repo instead, with two example calls which reproduce the issue: https://github.com/edimoldovan/hapi-mongo-models-example
If you do this:
curl -X POST -H "Content-Type: application/json; charset=utf-8" "127.0.0.1:8000/api/users" -d '{"email":"[email protected]","password":"bla","name":"name”}’
a user will be inserted, but not returned in the response. Also, if you hit this url:
http://localhost:8000/api/users
you will see that the data array contains the correct number of objects, only they are empty.
If I do the change I mentioned above, all this suddenly becomes ok.
from hapi-mongo-models.
Thanks so much. That made it much easier to help figure out why the objects were empty for you.
Your model was missing a constructor
. When we create a new instance of a model we pass the instance data into it's constructor
.
Here is what I did to fix your example.
$ npm install object-assign --save
Then in your model I added a constructor
:
var Joi = require('joi');
var BaseModel = require('hapi-mongo-models').BaseModel;
var ObjectAssign = require('object-assign');
var User = BaseModel.extend({
constructor: function (attrs) {
ObjectAssign(this, attrs);
}
});
User._collection = 'users'; // the mongo collection name
User.schema = Joi.object().keys({
name: Joi.string(),
image: Joi.string(),
password: Joi.string().required(),
email: Joi.string().email().required()
});
module.exports = User;
Then both GET
and POST
worked as expected.
from hapi-mongo-models.
Works very well, thank you for your help. The readme update would also be welcome, thate is where I copied my code from. Suppose will be done later.
from hapi-mongo-models.
Related Issues (20)
- Can't use Mongo Native method Aggregate HOT 3
- Not authorized on dbname to execute command HOT 1
- QUESTION: Does this plug-in support associations? HOT 2
- Issue with updateOne & update Many HOT 4
- server.start() to include Mongo models? HOT 3
- v6.0.0 release notes
- Add a modelsDirectory plugin option
- using aggregate function HOT 2
- Not expected results in v6.0.0 responses HOT 3
- Multiple db support HOT 1
- MongoDB custom logger HOT 1
- Unable to get the instantiated db reference. HOT 1
- Hapi v17 support HOT 1
- Migrate callbacks pattern to async/await (hapi v17)
- Support for ssh tunnel ? HOT 6
- models "path/to/customer" might be off? HOT 2
- Migration help HOT 1
- Plugin example for 7.x.x? HOT 3
- $elemMatch returns all subjects HOT 1
- If connection.db is optional, why is there an assertion error if it isn't provided? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi-mongo-models.