sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

issue seeding #3

Closed clds84 closed 2 years ago

clds84 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

I'm trying to seed data

Post any code you think might be relevant (one fenced block per file)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

when I run npm run seed, this is all I get without any seeding or confirmation of seeding:

> express-auth-mongoose-boilerplate@1.0.0 seed
> node app/models/seed.js

If I console log db, I get this along with the code above:


<ref *1> NativeConnection {
  base: Mongoose {
    connections: [ [Circular *1] ],
    models: { Project: Model { Project } },
    events: EventEmitter {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      [Symbol(kCapture)]: false
    },
    options: {
      pluralization: true,
      autoIndex: true,
      autoCreate: true,
      [Symbol(mongoose:default)]: true
    },
    _pluralize: [Function: pluralize],
    Schema: [Function: Schema] {
      reserved: [Object: null prototype],
      Types: [Object],
      ObjectId: [Function]
    },
    model: [Function (anonymous)],
    plugins: [ [Array], [Array], [Array], [Array], [Array], [Array] ]
  },
  collections: {
    projects: Collection {
      collection: null,
      Promise: [Function: Promise],
      modelName: 'Project',
      _closed: false,
      opts: [Object],
      name: 'projects',
      collectionName: 'projects',
      conn: [Circular *1],
      queue: [],
      buffer: true,
      emitter: [EventEmitter]
    }
  },
  models: { Project: Model { Project } },
  config: {},
  replica: false,
  options: null,
  otherDbs: [],
  relatedDbs: {},
  states: [Object: null prototype] {
    '0': 'disconnected',
    '1': 'connected',
    '2': 'connecting',
    '3': 'disconnecting',
    '99': 'uninitialized',
    disconnected: 0,
    connected: 1,
    connecting: 2,
    disconnecting: 3,
    uninitialized: 99
  },
  _readyState: 0,
  _closeCalled: false,
  _hasOpened: false,
  plugins: [],
  id: 0,
  _queue: [],
  _listening: false
}

What is your best guess as to the source of the problem?

I created the seed file with const mongoose = require('mongoose') even though I was using my project 2 as a template. Project 2 was const mongoose = require('./connection') but that's bc we had a connection model.

This is what my entire seed.js model looks like:

///////////////////////////////////////
// Import Dependencies
///////////////////////////////////////
//const mongoose = require('./connection')
const mongoose = require('mongoose')
const Project = require('./project')

///////////////////////////////////////////
// Seed Code
////////////////////////////////////////////
// save the connection in a variable
const db = mongoose.connection;

db.on('open', () => {
    // array of starter fruits
    const starterProject = {
        garmentType: "shirt",
        Fabric: "poplin",
        Interfacing:"medium-weight fusible",
        Notions:["rotary cutter", "shears","point turner"],
        pattern: "self-drafted",
    }

    // when we seed data, there are a few steps involved
    // delete all the data that already exists(will only happen if data exists)
    Project.remove({})
        .then(deletedProjects => {
            console.log('this is what remove returns', deletedProjects)
            // then we create with our seed data
            Project.create(starterProject)
                .then((data) => {
                    console.log('Here is the new seeded data re: starter projects', data)
                    db.close()
                })
                .catch(error => {
                    console.log(error)
                    db.close()
                })
        })
        .catch(error => {
            console.log(error)
            db.close()
        })
    // then we can send if we want to see that data
})

What things have you already tried to solve the problem?

When I tried running db, I get an object with info I'm unsure how to handle. I don't know if there's a clue somewhere in there that I'm missing.

Paste a link to your repository here

DoireannJane commented 2 years ago

Hey there! I see this was from last week, is this still an issue?