0

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:

enter image description here

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

dtjmsy
  • 2,664
  • 9
  • 42
  • 62
  • Questions seeking debugging help (**"why isn't this code working?"**) must include the desired behavior, a *specific problem or error and the shortest code necessary* to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – Neil Lunn Jun 28 '17 at 14:28
  • Hi Neil, i added it into the question the codes, i see, may be it' s the port, i check it – dtjmsy Jun 28 '17 at 14:32
  • You added a link to a tutorial. Don't expect someone else to debug that for you. Work out where the problem is and if you need to ask a question then ask that one. – Neil Lunn Jun 28 '17 at 14:33
  • Why would you need babel here anyway? Modern nodejs releases will process the ES6 without problem. Seems like it's an old tutorial. – Neil Lunn Jun 28 '17 at 14:35
  • the question is: how to launch the node_modules/babel-cli/bin/babel-node.js populate.js – dtjmsy Jun 28 '17 at 14:35
  • Neil: Modern nodejs releases will process the ES6 --> is there another way to run it without the babel-node.js command ? – dtjmsy Jun 28 '17 at 14:37

0 Answers0