Mongoose Atlas connection hangingHow do I update/upsert a document in Mongoose?NodeJs, Mocha and MongooseGet all documents of a type in mongoose but only with 1 specific item of each documents arrayUpdate Issues with Put Request, JQuery, MongoDB and MongooseMongoose sort by populated fieldPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).MongoDB/ Mongoose many to many relationship - user, project and roleWhy I can't retrieve any result when I use mongoose in my appMongoose Secondary Index is not createdMongoose pre.remove middleware of objects in array are never called

What class is best to play when a level behind the rest of the party?

What is Gilligan's full name?

Changing the PK column of a data extension without completely recreating it

Why are backslashes included in this shell script?

Can an escape pod land on Earth from orbit and not be immediately detected?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

How do I type a hyphen in iOS 12?

A team managed by my peer is close to melting down

What are some of the expected properties of metallic glasses and some steps to create them? (semi-ELI5)

usage of mir gefallen

Is it good practice to create tables dynamically?

Can an open source licence be revoked if it violates employer's IP?

Why would a car salesman tell me not to get my credit pulled again?

Is time complexity more important than space complexity?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

Nth term of Van Eck Sequence

Can I get a photo of an Ancient Arrow?

I sent an angry e-mail to my interviewers about a conflict at my home institution. Could this affect my application?

Why did Robert pick unworthy men for the White Cloaks?

Is fission/fusion to iron the most efficient way to convert mass to energy?

How to represent jealousy in a cute way?

Purpose of cylindrical attachments on Power Transmission towers

Simple log rotation script

Why are ambiguous grammars bad?



Mongoose Atlas connection hanging


How do I update/upsert a document in Mongoose?NodeJs, Mocha and MongooseGet all documents of a type in mongoose but only with 1 specific item of each documents arrayUpdate Issues with Put Request, JQuery, MongoDB and MongooseMongoose sort by populated fieldPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).MongoDB/ Mongoose many to many relationship - user, project and roleWhy I can't retrieve any result when I use mongoose in my appMongoose Secondary Index is not createdMongoose pre.remove middleware of objects in array are never called






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to abstract a tutorial for MEAN stack to use MongoAtlas rather than a local instance.
My Mongoose connection to Atlas DB is working (in so far as I can connect to the DB). But I'm not able to do a save(). I believe that this is something to do with the way I'm creating my connection object, but I don't seem to be able to put my finger on the problem.



I assumed that by adding bufferCommands = false that this would tell me that the reason it wasn't working was I'd opened the connection object wrongly, but I'm not seeing any error - just hanging.



product.js



var mongoose = require('mongoose');
var db = mongoose.connection;
var Schema = mongoose.Schema;

var schema = new Schema (
imagePath: type: String, required: true,
title: type: String, required: true,
description: type: String, required: true,
price: type: Number, required:true
);
var connection = mongoose.createConnection('mongodb+srv://<user>:<password>@cluster0-dpwmr.gcp.mongodb.net/Shopping?retryWrites=true', useNewUrlParser:true)

module.exports = connection.model('Product', schema);


product-seeder.js



var Product = require('../models/product');

var mongoose = require('mongoose');
//mongoose.set('bufferCommands', false);
var products =[
new Product(
imagePath:'https://picsum.photos/250/?random',
title: 'Item 1',
description: 'This is a thing',
price: 10
),
new Product(
imagePath:'https://picsum.photos/251/?random',
title: 'Item 2',
description: 'This is another thing',
price: 14
),
new Product(
imagePath:'https://picsum.photos/253/?random',
title: 'Item 3',
description: 'This is a slightly longer description',
price: 30
)
];


var done = 0;
for (i=0; i++; i<products.length)
products[i].save(function(err, res)
if (err)
console.log(err);
exit();

done++;
if (done === products.length)
exit();

);


function exit()
mongoose.disconnect();



I expected this to create a new document 'products' and write to it in the Shopping collection, but that's not happening, just lots of nothing.










share|improve this question






















  • Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

    – Moad Ennagi
    Mar 26 at 7:50

















0















I'm trying to abstract a tutorial for MEAN stack to use MongoAtlas rather than a local instance.
My Mongoose connection to Atlas DB is working (in so far as I can connect to the DB). But I'm not able to do a save(). I believe that this is something to do with the way I'm creating my connection object, but I don't seem to be able to put my finger on the problem.



I assumed that by adding bufferCommands = false that this would tell me that the reason it wasn't working was I'd opened the connection object wrongly, but I'm not seeing any error - just hanging.



product.js



var mongoose = require('mongoose');
var db = mongoose.connection;
var Schema = mongoose.Schema;

var schema = new Schema (
imagePath: type: String, required: true,
title: type: String, required: true,
description: type: String, required: true,
price: type: Number, required:true
);
var connection = mongoose.createConnection('mongodb+srv://<user>:<password>@cluster0-dpwmr.gcp.mongodb.net/Shopping?retryWrites=true', useNewUrlParser:true)

module.exports = connection.model('Product', schema);


product-seeder.js



var Product = require('../models/product');

var mongoose = require('mongoose');
//mongoose.set('bufferCommands', false);
var products =[
new Product(
imagePath:'https://picsum.photos/250/?random',
title: 'Item 1',
description: 'This is a thing',
price: 10
),
new Product(
imagePath:'https://picsum.photos/251/?random',
title: 'Item 2',
description: 'This is another thing',
price: 14
),
new Product(
imagePath:'https://picsum.photos/253/?random',
title: 'Item 3',
description: 'This is a slightly longer description',
price: 30
)
];


var done = 0;
for (i=0; i++; i<products.length)
products[i].save(function(err, res)
if (err)
console.log(err);
exit();

done++;
if (done === products.length)
exit();

);


function exit()
mongoose.disconnect();



I expected this to create a new document 'products' and write to it in the Shopping collection, but that's not happening, just lots of nothing.










share|improve this question






















  • Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

    – Moad Ennagi
    Mar 26 at 7:50













0












0








0








I'm trying to abstract a tutorial for MEAN stack to use MongoAtlas rather than a local instance.
My Mongoose connection to Atlas DB is working (in so far as I can connect to the DB). But I'm not able to do a save(). I believe that this is something to do with the way I'm creating my connection object, but I don't seem to be able to put my finger on the problem.



I assumed that by adding bufferCommands = false that this would tell me that the reason it wasn't working was I'd opened the connection object wrongly, but I'm not seeing any error - just hanging.



product.js



var mongoose = require('mongoose');
var db = mongoose.connection;
var Schema = mongoose.Schema;

var schema = new Schema (
imagePath: type: String, required: true,
title: type: String, required: true,
description: type: String, required: true,
price: type: Number, required:true
);
var connection = mongoose.createConnection('mongodb+srv://<user>:<password>@cluster0-dpwmr.gcp.mongodb.net/Shopping?retryWrites=true', useNewUrlParser:true)

module.exports = connection.model('Product', schema);


product-seeder.js



var Product = require('../models/product');

var mongoose = require('mongoose');
//mongoose.set('bufferCommands', false);
var products =[
new Product(
imagePath:'https://picsum.photos/250/?random',
title: 'Item 1',
description: 'This is a thing',
price: 10
),
new Product(
imagePath:'https://picsum.photos/251/?random',
title: 'Item 2',
description: 'This is another thing',
price: 14
),
new Product(
imagePath:'https://picsum.photos/253/?random',
title: 'Item 3',
description: 'This is a slightly longer description',
price: 30
)
];


var done = 0;
for (i=0; i++; i<products.length)
products[i].save(function(err, res)
if (err)
console.log(err);
exit();

done++;
if (done === products.length)
exit();

);


function exit()
mongoose.disconnect();



I expected this to create a new document 'products' and write to it in the Shopping collection, but that's not happening, just lots of nothing.










share|improve this question














I'm trying to abstract a tutorial for MEAN stack to use MongoAtlas rather than a local instance.
My Mongoose connection to Atlas DB is working (in so far as I can connect to the DB). But I'm not able to do a save(). I believe that this is something to do with the way I'm creating my connection object, but I don't seem to be able to put my finger on the problem.



I assumed that by adding bufferCommands = false that this would tell me that the reason it wasn't working was I'd opened the connection object wrongly, but I'm not seeing any error - just hanging.



product.js



var mongoose = require('mongoose');
var db = mongoose.connection;
var Schema = mongoose.Schema;

var schema = new Schema (
imagePath: type: String, required: true,
title: type: String, required: true,
description: type: String, required: true,
price: type: Number, required:true
);
var connection = mongoose.createConnection('mongodb+srv://<user>:<password>@cluster0-dpwmr.gcp.mongodb.net/Shopping?retryWrites=true', useNewUrlParser:true)

module.exports = connection.model('Product', schema);


product-seeder.js



var Product = require('../models/product');

var mongoose = require('mongoose');
//mongoose.set('bufferCommands', false);
var products =[
new Product(
imagePath:'https://picsum.photos/250/?random',
title: 'Item 1',
description: 'This is a thing',
price: 10
),
new Product(
imagePath:'https://picsum.photos/251/?random',
title: 'Item 2',
description: 'This is another thing',
price: 14
),
new Product(
imagePath:'https://picsum.photos/253/?random',
title: 'Item 3',
description: 'This is a slightly longer description',
price: 30
)
];


var done = 0;
for (i=0; i++; i<products.length)
products[i].save(function(err, res)
if (err)
console.log(err);
exit();

done++;
if (done === products.length)
exit();

);


function exit()
mongoose.disconnect();



I expected this to create a new document 'products' and write to it in the Shopping collection, but that's not happening, just lots of nothing.







node.js mongodb mongoose mongoose-schema






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 0:18









MrRikMrRik

11




11












  • Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

    – Moad Ennagi
    Mar 26 at 7:50

















  • Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

    – Moad Ennagi
    Mar 26 at 7:50
















Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

– Moad Ennagi
Mar 26 at 7:50





Have you tried using mongoose.connect() instead of mongoose.createConnection, it's been related to some issues.

– Moad Ennagi
Mar 26 at 7:50












1 Answer
1






active

oldest

votes


















0














I've got this working with a combination of:



  • Using mongoose.connect()

  • Adding the DB name to the options object

  • Making sure that the DB writes are done with proper promises, not weird loops.

var mongoose = require('mongoose');
var db = mongoose.connection;
var Schema = mongoose.Schema;

var schema = new Schema (
imagePath: type: String, required: true,
title: type: String, required: true,
description: type: String, required: true,
price: type: Number, required:true
);
mongoose.connect('mongodb+srv://<UserName>:<Password>@cluster0-dpwmr.gcp.mongodb.net/', dbName:'Shopping', useNewUrlParser:true)
.then( () =>
console.log('Connection to the Atlas Cluster is successful!')
)
.catch( (err) => console.error(err));

const conn = mongoose.connection;
module.exports = mongoose.model('Product', schema);


var Product = require('../models/product');

var mongoose = require('mongoose');

var products =[
new Product(
imagePath:'https://picsum.photos/250/?random',
title: 'Item 1',
description: 'This is a thing',
price: 10
),
new Product(
imagePath:'https://picsum.photos/251/?random',
title: 'Item 2',
description: 'This is another thing',
price: 14
),
new Product(
imagePath:'https://picsum.photos/253/?random',
title: 'Item 3',
description: 'This is a slightly longer description',
price: 30
)
];
const conn = mongoose.connection;

processArray(products);

async function processArray (array)
for (const item of products)
console.log (item)
await item.save();

conn.close();







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329856%2fmongoose-atlas-connection-hanging%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've got this working with a combination of:



    • Using mongoose.connect()

    • Adding the DB name to the options object

    • Making sure that the DB writes are done with proper promises, not weird loops.

    var mongoose = require('mongoose');
    var db = mongoose.connection;
    var Schema = mongoose.Schema;

    var schema = new Schema (
    imagePath: type: String, required: true,
    title: type: String, required: true,
    description: type: String, required: true,
    price: type: Number, required:true
    );
    mongoose.connect('mongodb+srv://<UserName>:<Password>@cluster0-dpwmr.gcp.mongodb.net/', dbName:'Shopping', useNewUrlParser:true)
    .then( () =>
    console.log('Connection to the Atlas Cluster is successful!')
    )
    .catch( (err) => console.error(err));

    const conn = mongoose.connection;
    module.exports = mongoose.model('Product', schema);


    var Product = require('../models/product');

    var mongoose = require('mongoose');

    var products =[
    new Product(
    imagePath:'https://picsum.photos/250/?random',
    title: 'Item 1',
    description: 'This is a thing',
    price: 10
    ),
    new Product(
    imagePath:'https://picsum.photos/251/?random',
    title: 'Item 2',
    description: 'This is another thing',
    price: 14
    ),
    new Product(
    imagePath:'https://picsum.photos/253/?random',
    title: 'Item 3',
    description: 'This is a slightly longer description',
    price: 30
    )
    ];
    const conn = mongoose.connection;

    processArray(products);

    async function processArray (array)
    for (const item of products)
    console.log (item)
    await item.save();

    conn.close();







    share|improve this answer



























      0














      I've got this working with a combination of:



      • Using mongoose.connect()

      • Adding the DB name to the options object

      • Making sure that the DB writes are done with proper promises, not weird loops.

      var mongoose = require('mongoose');
      var db = mongoose.connection;
      var Schema = mongoose.Schema;

      var schema = new Schema (
      imagePath: type: String, required: true,
      title: type: String, required: true,
      description: type: String, required: true,
      price: type: Number, required:true
      );
      mongoose.connect('mongodb+srv://<UserName>:<Password>@cluster0-dpwmr.gcp.mongodb.net/', dbName:'Shopping', useNewUrlParser:true)
      .then( () =>
      console.log('Connection to the Atlas Cluster is successful!')
      )
      .catch( (err) => console.error(err));

      const conn = mongoose.connection;
      module.exports = mongoose.model('Product', schema);


      var Product = require('../models/product');

      var mongoose = require('mongoose');

      var products =[
      new Product(
      imagePath:'https://picsum.photos/250/?random',
      title: 'Item 1',
      description: 'This is a thing',
      price: 10
      ),
      new Product(
      imagePath:'https://picsum.photos/251/?random',
      title: 'Item 2',
      description: 'This is another thing',
      price: 14
      ),
      new Product(
      imagePath:'https://picsum.photos/253/?random',
      title: 'Item 3',
      description: 'This is a slightly longer description',
      price: 30
      )
      ];
      const conn = mongoose.connection;

      processArray(products);

      async function processArray (array)
      for (const item of products)
      console.log (item)
      await item.save();

      conn.close();







      share|improve this answer

























        0












        0








        0







        I've got this working with a combination of:



        • Using mongoose.connect()

        • Adding the DB name to the options object

        • Making sure that the DB writes are done with proper promises, not weird loops.

        var mongoose = require('mongoose');
        var db = mongoose.connection;
        var Schema = mongoose.Schema;

        var schema = new Schema (
        imagePath: type: String, required: true,
        title: type: String, required: true,
        description: type: String, required: true,
        price: type: Number, required:true
        );
        mongoose.connect('mongodb+srv://<UserName>:<Password>@cluster0-dpwmr.gcp.mongodb.net/', dbName:'Shopping', useNewUrlParser:true)
        .then( () =>
        console.log('Connection to the Atlas Cluster is successful!')
        )
        .catch( (err) => console.error(err));

        const conn = mongoose.connection;
        module.exports = mongoose.model('Product', schema);


        var Product = require('../models/product');

        var mongoose = require('mongoose');

        var products =[
        new Product(
        imagePath:'https://picsum.photos/250/?random',
        title: 'Item 1',
        description: 'This is a thing',
        price: 10
        ),
        new Product(
        imagePath:'https://picsum.photos/251/?random',
        title: 'Item 2',
        description: 'This is another thing',
        price: 14
        ),
        new Product(
        imagePath:'https://picsum.photos/253/?random',
        title: 'Item 3',
        description: 'This is a slightly longer description',
        price: 30
        )
        ];
        const conn = mongoose.connection;

        processArray(products);

        async function processArray (array)
        for (const item of products)
        console.log (item)
        await item.save();

        conn.close();







        share|improve this answer













        I've got this working with a combination of:



        • Using mongoose.connect()

        • Adding the DB name to the options object

        • Making sure that the DB writes are done with proper promises, not weird loops.

        var mongoose = require('mongoose');
        var db = mongoose.connection;
        var Schema = mongoose.Schema;

        var schema = new Schema (
        imagePath: type: String, required: true,
        title: type: String, required: true,
        description: type: String, required: true,
        price: type: Number, required:true
        );
        mongoose.connect('mongodb+srv://<UserName>:<Password>@cluster0-dpwmr.gcp.mongodb.net/', dbName:'Shopping', useNewUrlParser:true)
        .then( () =>
        console.log('Connection to the Atlas Cluster is successful!')
        )
        .catch( (err) => console.error(err));

        const conn = mongoose.connection;
        module.exports = mongoose.model('Product', schema);


        var Product = require('../models/product');

        var mongoose = require('mongoose');

        var products =[
        new Product(
        imagePath:'https://picsum.photos/250/?random',
        title: 'Item 1',
        description: 'This is a thing',
        price: 10
        ),
        new Product(
        imagePath:'https://picsum.photos/251/?random',
        title: 'Item 2',
        description: 'This is another thing',
        price: 14
        ),
        new Product(
        imagePath:'https://picsum.photos/253/?random',
        title: 'Item 3',
        description: 'This is a slightly longer description',
        price: 30
        )
        ];
        const conn = mongoose.connection;

        processArray(products);

        async function processArray (array)
        for (const item of products)
        console.log (item)
        await item.save();

        conn.close();








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 1:10









        MrRikMrRik

        11




        11





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329856%2fmongoose-atlas-connection-hanging%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현