ericnograles / agilemoviedb Goto Github PK
View Code? Open in Web Editor NEWAgileMovieDB: A sample app for a MEAN world
AgileMovieDB: A sample app for a MEAN world
Hi, I came across your project while searching for strategies for seeding my sails.js project with data it needs. I am using Sails 0.10.x.
I've followed your example just fine (Thanks for the blog btw, it was educational), making changes where needed for Sails 0.10.x, but I am having issues with the following line
new Movie({ adapters: { mongo: mongoAdapter }}, function(err, collection) {
I just can't work out what needs to be there.
My config/connections.js
looks like:
module.exports.connections = {
development: {
adapter : 'sails-mongo',
host : 'localhost',
port : 27017,
user : 'myuser',
password : 'mypass',
database : 'mydb'
}
};
and my data/seeds.js
looks like
var _ = require("lodash"),
Waterline = require("waterline"),
connectionsConfig = require("../config/connections"),
dbEnv = process.env.NODE_ENV || 'development',
connection = connectionsConfig.connections[dbEnv],
mongoAdapter = require(connection.adapter),
Promise = require("promise"), mongoUrl;
console.log("connecting with ", connection);
// Match our config
mongoUrl = "mongodb://" +
connection.user + ":" + connection.password + "@" +
connection.host + ":" + connection.port + "/" +
connection.database;
mongoAdapter.database = connection.database;
mongoAdapter.host = connection.host;
mongoAdapter.port = connection.port;
mongoAdapter.user = connection.user;
mongoAdapter.password = connection.password;
mongoAdapter.config = {
url: mongoUrl
};
/**
* Seeds locations in a promise-y way
*/
var seedLocation = function() {
console.log("seeding Locations");
var LocationModel = require("../api/models/Location"),
locationData = require("./locations.json");
console.log("LocationModel", LocationModel);
console.log("locationData", locationData.length);
return new Promise(
function(fulfill, reject) {
// Seed Location Data from our JSON
LocationModel.adapter = dbEnv;
var Location = Waterline.Collection.extend(LocationModel);
// Invoke Waterline
new Location({ adapters: mongoAdapter }, function(err, collection) {
if (err){
console.error("There was a problem initializing the Location collection.");
} else {
// First nuke all existing Locations
collection.destroy().done(function(err, deletedLocations) {
console.log("Successfully deleted " + deletedLocations.length + " Locations!");
collection.createEach(locationData, function(err, models) {
if (err || _.isUndefined(models)) {
console.log("Could not create Location collection!");
fulfill();
} else {
console.log("Successfully inserted Locations");
collection.find().done(function(err, existingLocations) {
fulfill(existingLocations);
});
}
});
});
}
});
}
);
};
// Node.js: fulfilling more promises than all politicians combined in history
seedLocation().then(function(locations) {
console.log("Seeded" + locations.length + " locations");
process.exit();
}, function(err){
console.log("Seeding failed", err.stack);
});
The error I get is
Seeding failed TypeError: Cannot read property 'undefined' of undefined
at Core._initialize (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/core/index.js:70:47)
at module.exports (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/core/index.js:50:20)
at module.exports (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/collection/index.js:44:8)
at new child (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/utils/extend.js:17:39)
at /Users/dave/src/myproject/data/seeds.js:45:32
at new Promise (/Users/dave/src/myproject/node_modules/promise/index.js:42:5)
at seedLocation (/Users/dave/src/myproject/data/seeds.js:38:10)
at Object.<anonymous> (/Users/dave/src/myproject/data/seeds.js:71:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I am using waterline
version 0.10.0-rc9
and sails 0.10.0-rc8
cheers and thanks in advance
dave
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.