I am following this tutorial: http://rationalappdev.com/api-backend-with-nodejs-express-and-mongodb-for-react-native-apps/
basically, I am trying to create a MongoDB on windows and populate it with some datas in a movie.js file
I launch the command node_modules/babel-cli/bin/babel-node.js populate.js, however, i got an error message, compilation error, line 1:
I check the MongoDB, with mongo.exe command line (db.people.save({"name": "son"})), it works fine.
the mongo db port is 27017
This is the movie.js code:
import mongoose from 'mongoose';
import Movie from './models/movie';
const movies = [
{
title: 'La La Land',
poster: 'https://i.imgur.com/po7UezG.jpg',
genre: 'Drama/Romance',
},
{
title: 'Paterson',
poster: 'https://i.imgur.com/pE0C9E0.jpg',
genre: 'Drama/Comedy',
},
{
title: 'Jackie',
poster: 'https://i.imgur.com/VqUi1sw.jpg',
genre: 'Drama/Biography',
},
{
title: 'Zoolander 2',
poster: 'https://i.imgur.com/ejlIijD.jpg',
genre: 'Comedy',
},
];
// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/movies');
// Go through each movie
movies.map(data => {
// Initialize a model with movie data
const movie = new Movie(data);
// and save it into the database
movie.save();
});
This is the model/movie.js:
import mongoose, { Schema } from 'mongoose';
// Define movie schema
var movieSchema = new Schema({
title: {
type: String,
unique: true,
},
poster: String,
genre: String,
days: Array,
times: Array,
});
// Export Mongoose model
export default mongoose.model('movie', movieSchema);
Do you have any idea why does it happens, as i changed the mongoDB port mongoose.connect('mongodb://127.0.0.1:27017/movies'); doesn' t help, check the package.json to make sure babel-node.js is in the node-modules/babel-cli/bin directory, test the mongodb alone, running out of ideas
Thanks