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 8013999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:47:57+00:00 2026-06-04T19:47:57+00:00

I have tried everything I could and I googled and found some examples, I

  • 0

I have tried everything I could and I googled and found some examples, I tried the examples and no joy. I’m really stuck now. So, I have mongodb on my Mac which I installed via brew. It went well. I start the server by “mongod” and it also went well. I insert some data on mongo interactive, which you can see below when I retrieved the data. I have database name “test” and collection “test”


> db.test.find()
{ "_id" : ObjectId("4fc27535a36ea778dd6cbdf4"), "a" : "1" }
{ "_id" : ObjectId("4fc27557a36ea778dd6cbdf5"), "Ich" : "I" }

Now, when I create a simple mocha test with mongoose with this code.


var Vocabulary = function() {

    function get(german_vocab) {
        var mongoose = require("mongoose");
        mongoose.connect('mongodb://localhost:27017/test');
        mongoose.connection.on("open", function(){
          console.log("mongodb is connected!!");
        });

        mongoose.connection.db.collection("test", function (err, collection) {
            collection.find().toArray(function(err, results) {
                console.log(results);
            });
        });
    }

    return {
        get : get
    };
}

module.exports = Vocabulary;

And this is my mocha test


var should = require('should');
var Vocabulary = require('../modules/vocabulary');

describe("Vocabulary", function() {
    it("should get a translation of Ich", function() {
        var vocabulary = Vocabulary();
        vocabulary.get("Ich");
    });
});

This is what I get from Mocha



  Vocabulary
    ✓ should get a translation of Ich (161ms)


  ✔ 1 test complete (163ms)


As you can see it doesn’t ever print “mongodb is connected!” and on the find() method it also doesn’t print anything.

Please help me out. Thank you so much.

  • 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-04T19:47:59+00:00Added an answer on June 4, 2026 at 7:47 pm

    I think the basic problem is that you’re trying to take a synchronous approach to asynchronous activities. For example:

    1. Your mongoose connection to the database isn’t actually open until you get the “open” event callback.
    2. Your get method should be returning the results in a callback that’s passed into the function.
    3. Your mocha test should be using the asynchronous style where you call the done function parameter that’s passed into your it callback when your test is complete.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm encountering a huge problem, I have tried everything I could, but I didn't
I've tried everything Google and StackOverflow have recommended (that I could find) including using
I have tried everything in the book and EVERYTHING I could find on how
I have tried everything, searched the net for two hours or even more and
Having an issue here that I have tried everything I can think of but
I have tried to draw a bar in a cell of my table. Everything
I've tried almost everything. In my nginx.conf I have rails_env set to production in
Have tried to find solutions for this and can't really come up with anything.
I'm a wee bit stuck on this, and was hoping you might have some
I am new at this and stuck for days...trying everything I could find from

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.