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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?