Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:36:51+00:00 2026-06-09T20:36:51+00:00

I’m trying to learn node and mongo in order to build a simple web

  • 0

I’m trying to learn node and mongo in order to build a simple web app/teach myself a little bit more about web applications. However, when I call Model.save(), the continuation function never seems to execute, and the data isn’t saved.

Here’s what I have so far:

/* app.js */

var express = require('express')
  , app = express()
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , mongoose = require('mongoose')
  , db 
  , Track
  , models = require('./models.js');

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('secretstuff'));
  app.use(express.session());
  app.use(app.router);
  app.use(require('less-middleware')({ src: __dirname + '/public' }));
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(function(err, req, res, next){
    console.error(err.stack);
    res.send(500, 'Something broke!');
  });
});

models.defineModels(mongoose, function(){
  app.Track = Track = mongoose.model('Track');
  db = mongoose.createConnection('localhost','nextrak')
});

app.get('/', routes.index);

app.get('/dbTest', function(req, res){
  console.log("Here goes...");
  var t = new Track({
    name: "TestTrack",
    artist: "Artist",
    tags: ["test"],
    next: ["track1","track2"]
  });
  console.log("Test Track:");
  console.log(t);

  t.save(function(){
    if(err)
      console.log("Error! Couldn't complete dbTest successfully.");
    else
      console.log("Aw yiss, got dbTest working");
  })
});

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});


/*models.js*/

function defineModels(mongoose, cont){
  var Schema = mongoose.Schema;
  Track = new Schema({
    'name': { type: String, index: true },
    'artist': String,
    'tags': [String],
    'next': [String],
  });
  mongoose.model('Track', Track);
  cont();
}

exports.defineModels = defineModels;

No errors are thrown, and the mongo logs indicate that 5 new connections are spun up when I launch my app. No new logs appear (except [clientcursormon] logs). The app prints out the following when I load /dbTest in Chrome:

Here goes…

  Test Track:
    { name: 'TestTrack',
      artist: 'Basik',
      _id: 5031606aa11cf95815000001,
      next: [ 'track1', 'track2' ],
      tags: [ 'test' ] }

Mongo appears to be configured correctly. When I have node run the simple “Getting Started” script that Mongoose walks you through, everything works correctly.

Can anyone point out what I’m doing incorrectly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:36:52+00:00Added an answer on June 9, 2026 at 8:36 pm

    You haven’t created a connection for Mongoose to use by default. Replace this:

    db = mongoose.createConnection('localhost','nextrak')
    

    With this:

    db = mongoose.connect('localhost', 'nextrak');
    

    Couple other nits:

    1. You’re setting Track as a global variable in models.js
    2. You need to add a err parameter to your t.save callback.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.