These are chat archives for Automattic/mongoose

7th
Feb 2018
Ambika Kumar
@ambikarajbadal
Feb 07 2018 05:59
Please help me......//Mongo connection
mongoose.connect('mongodb://localhost/webapp',(error)=>{
if(error) throw error;
console.log('Mongodb Connected');
});
and it run successfully.... nodemon
[nodemon] 1.14.12
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node app.js
Server is running on port 5000
Mongodb Connected
but when i fire the command show dbs; then in database list webapp database is not available.
Kev
@lineus
Feb 07 2018 08:12
@ambikarajbadal can you paste the code or a ink to a gist of the code that your using to show the dbs?
Kev
@lineus
Feb 07 2018 08:47
add a comment to your gist, I hope it helps @ambikarajbadal .
Ambika Kumar
@ambikarajbadal
Feb 07 2018 10:30
Hey @lineus you can see in the line 10 of snippets, I assign the name of database which is "webapp". i think when i run the app.js then it should be automatically created database with the name of "webapp" in my mongodb but it not happen like that.
Ambika Kumar
@ambikarajbadal
Feb 07 2018 10:38
@lineus For better understanding please visite this link and see the image. https://imgur.com/a/J4aXj
Kev
@lineus
Feb 07 2018 10:44

just to be clear, you are expecting code like the following to create the database?

#!/usr/bin/env node
'use strict'

const mongoose = require('mongoose')

const conn = mongoose.connect('mongodb://localhost/isthisgoingtowork')
conn.then(function () {
  console.log('connected')
})
output in mongo shell:
> show dbs
admin  0.000GB
local  0.000GB

when I test this there is no db created in monogdb. however, once I create a model (collection) and save an instance, both the db and the collection, and the document get created. for example in the following code:

#!/usr/bin/env node
'use strict'

const mongoose = require('mongoose')
const M = mongoose.model('testing', new mongoose.Schema({
  name: String
}))
const conn = mongoose.connect('mongodb://localhost/isthisgoingtowork')
conn.then(function () {
  console.log('connected')
  let m = new M({ name: 'billy' })
  m.save(function (err, res) {
    console.log(res)
  })
})
output in mongo shell:
> show dbs
admin              0.000GB
isthisgoingtowork  0.000GB
local              0.000GB
Kev
@lineus
Feb 07 2018 10:58
did you try the changes I suggested in the gist? i added a comment with a detailed explanation of why your original example wasn't going to work.
Ambika Kumar
@ambikarajbadal
Feb 07 2018 11:06
But i have also already created schema and model in another file and link it. please check it out ... https://imgur.com/0URU1Mz
Kev
@lineus
Feb 07 2018 11:07
I explain in my comment why your model wont work.
you have to export something from the idea.js file or you'll just wind up with an empty object as demonstrated in the last comment.
Ben Chiciudean
@benydc
Feb 07 2018 18:17
does mongoose Scheme handle promises by default now?
Kev
@lineus
Feb 07 2018 19:37
I don't think the schema itself specifically does, but models, connections, queries, and documents do.
Kev
@lineus
Feb 07 2018 19:46
you don't need to explicitly set the promise library anymore, it defaults to global.Promise.
Ben Chiciudean
@benydc
Feb 07 2018 19:47
I used bluebird, thanks
Kev
@lineus
Feb 07 2018 19:47
you can still set that like you did before afaik
what do you get from bluebird that isn't in global? I've never used it....
Yogendra Rawal
@rawalyogendra
Feb 07 2018 19:50
i need help regarding mongoose discriminator
help me please
@lineus please
Kev
@lineus
Feb 07 2018 19:54
I'll try :)
what's up?
@rawalyogendra ^