Comments (6)
Updated to node v6.9.1 and now I get this error:
Error: Property not allowed { undefined } for ClientApp Entity
at Object.keys.forEach (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/model.js:879:37)
at Array.forEach (native)
at ModelInstance.validate (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/model.js:856:38)
at Promise (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/schema.js:60:23)
at ModelInstance.fn (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/schema.js:58:20)
at ModelInstance.next (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:109:44)
at Promise (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:116:29)
at ModelInstance.wrapper [as save] (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:71:20)
at create (/Users/digaresc/t/src/sdk-backend/controllers/clientApp.controller.js:19:15)
at Layer.handle [as handle_request] (/Users/digaresc/t/src/sdk-backend/node_modules/express/lib/router/layer.js:95:5)
from gstore-node.
Hi,
I can't spot the error so let me write how it "should" work and see from there.
You need node > 4 (so 6.9.1 is perfect)
// server.js
// This is your main starting file
var datastore = require('@google-cloud/datastore')({
projectId: 'tttttttt',
keyFilename: './keyfile.json'
});
var gstore = require('gstore-node');
gstore.connect(datastore);
// ... rest of your initial setup
// client-app.model.js
var gstore = require('gstore-node');
var uuid = require('uuid');
var Schema = gstore.Schema;
var schema = new Schema({
appName: {
type: 'string',
required: true,
read: false
},
androidBundleId: {
type: 'string',
required: true,
read: false
},
iosBundleId: {
type: 'string',
required: true,
read: false
},
modified: {
type: 'boolean',
default: false,
read: false,
write: false
},
createdOn: {
type: 'datetime',
default: gstore.defaultValues.NOW,
write: false,
read: false
},
appKey: {
type: 'string',
default: uuid.v4(), // careful as this value will be "static" for all instance. I will add a fix to that soon
write: false
}
});
schema.virtual('timestamp').get(function() {
// the scope (this) is the entityData object
return this.createdOn;
});
var ClientAppModel = gstore.model('ClientApp', schema); // don't suffix "Model" to the entity kind.
module.exports = ClientAppModel;
// client-app.controller.js
var ClientAppModel = require('../models/client-app.model.js');
function create(req, res) {
var data = ClientAppModel.sanitize(req.body);
var clientApp = new ClientAppModel(data, data.appName);
delete data.appName; // You probably don't need it anymore as it is now the 'id'
clientApp.save().then(function() {
res.json(this.plain());
}).catch((err) => {
console.log(err);
res.status(400).json(err);
});
}
module.exports = {
create: create
};
from gstore-node.
Same problem.
Do you want me do do something else?
If I do a:
console.log(clientapp.entityData)
I got this, isn't there something strange?
I have been following all the the steps.
{ appName: 'Yikes',
androidBundleId: 'com.yikes.android',
iosBundleId: 'com.yikes.ios',
modified: false,
createdOn: 2016-12-02T19:41:49.885Z,
appKey: '51a22620-92b3-4c21-8125-0c6e7b3b98c0',
undefined:
Key {
namespace: undefined,
name: 'Yikes',
kind: 'ClientApp',
path: [Getter] } }
Thanks in advance.
from gstore-node.
Where do you do this console.log? If you did it inside the resolve of the Promise, it means that it did work and the entity should be saved in the datastore.
Also, have you tried saving a 'ClientApp' entity without gstore-node? Like in the example here: https://github.com/GoogleCloudPlatform/google-cloud-node#preview-2 to make sure your settings are ok.
from gstore-node.
Found the problem. The problem was that I had installed an older version of google datastore and I installed on top gstore-node. After I removed the older version everything worked perfect.
Probably because I started with one of the GoogleCloudPlatform/nodejs-docs-samples that had an older version. My bad.
Thanks for the fast support.
Happy to help around here.
from gstore-node.
Great, happy you found the solution.
PS: just one thing about your example. For now, gstore does not "render" what is set in the "default" value. I will add this feature soon. So your default to uuid.v4() will be the same value for all your entities... If you want this, great, otherwise for now you have to manually set it before saving.
from gstore-node.
Related Issues (20)
- query filter on nested property value. HOT 5
- tsc error: Could not find a declaration file for module 'nsql-cache' HOT 3
- could not get data filter by entity key
- Support for @google-cloud/datastore version 5 HOT 2
- Support for custom validators (AJV)
- bulk insert? HOT 2
- Cannot read property 'Symbol(KEY)' when body is null or undefined HOT 1
- Typescript Compile Error HOT 2
- Support for HABTM
- Could not find gstore instance with id "${id}" HOT 2
- How to validate a value agains another property? HOT 1
- Datastore Key type error when using cache HOT 7
- Update method doesn't clear cache HOT 6
- Add Transaction support to `findOne` option HOT 1
- Support filtering for a missing optional property. HOT 1
- New query operators HOT 1
- @google-cloud/datastore version 7 support HOT 1
- could not get data filter by entity key HOT 1
- Migrate Travis CI builds to Circle CI
- Gstore node 7.2.8 TypeError: OptionalDataloader is not a constructor
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 gstore-node.