-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'createQuery' of undefined #10
Comments
Humm.. that's strange. I just double checked the Url.query().run(...) to make sure it was not broke but it works on my side. Can you double check the version of gstore-node (v0.6.1) and google-cloud (v0.38.3) Try also this for the connection:
|
From the package.json:
if it will help, I can make an sscce. |
tested with your minor change: var ds = gcloud.datastore();
gstore.connect(ds); It made no difference |
I am currently working on a demo app still in active development but have a look at how the controller and model are declared. Check main.js (root folder), blog-post.model.js and blog-post.controller.js https://github.com/sebelga/blog-app-googlecloud/tree/develop Your initial code seems ok and it's hard to debug without an example. |
my error is in my config. Instead of passing the file name to the keyFilename property, I was requiring the file and passing the json to it. {
projectId: 'project_id',
keyFilename: 'file.json'
} |
on further analysis, this error is related to external files creating & using models without the benefit of the existing datastore instance created on the gstore-object. This is something you'll see a lot in express code. The model in an external file is fine, until you import it in your controller where the gstore object was never declared. Then things start to fall apart. |
I'm re-opening this as a bug. The way mongoose works, you don't need a complete connection to create a model. In gstore-node, I need to create the datastore object/connection in my model files so that when I pull in the models elsewhere they work acceptably. Here's a demo of what I'm talking about. Creating a model before creating a connection is what breaks everything. var cloudJson = require('./cloud.json');
var gstore = require('gstore-node');
var Schema = gstore.Schema;
var urlSchema = new Schema({
name: { type: 'String', excludeFromIndexes: true },
subdomain: { type: 'String' }
});
var Url = gstore.model('url', urlSchema);
var configGcloud = {
projectId: cloudJson.project_id,
keyFilename: 'cloud.json'
};
var gcloud = require('google-cloud')(configGcloud);
var ds = gcloud.datastore();
gstore.connect(ds);
Url.query().run(function (err, urls) {
if (err) { return console.error(err); }
console.log(urls);
}); |
I see, you're right. I just changed the order of my require (putting the models declaration first) and I reproduced the bug. I will have a look into it. Thanks for reporting! |
I just released a version that should fix this problem. I am closing this issue, feel free to come back if the problem persists. |
As a user of mongoose, wanting to start switching to google cloud datastore, this library is ideal for me, thank you so much for making it.
So I created a connection:
Then I created a schema and made it into a model:
I don't know what step I might be missing in the docs, but when I try to query my new model:
I get the above error (it doesn't even make it to the
console.error
line. Specifically, it points to line924
ofmodel.js
in gstore-node:For some reason, the datastore is supposed to be passed in when creating the model, but is not. Given that there is a line 924 of model.js in the lib/ folder or gstore-node, at this point I'm pretty sure I'm in over my head and could use some guidance.
Did I do something wrong in the process of creating my model? Note that if I dump the
Url
object, it has a ds property with a datastore. object on it. In fact, if I dump theself
object in model.js, It contains theUrl
complete with the attached datastore, but for some reasonself.ds
is undefined.The text was updated successfully, but these errors were encountered: