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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:03:54+00:00 2026-06-04T07:03:54+00:00

The script I am working with is here: https://gist.github.com/2759751 I want to modify some

  • 0

The script I am working with is here: https://gist.github.com/2759751

I want to modify some code to store a streaming, parsed message from a node.js app to a mongodb collection for later access. So far I am working with tutorial code and am confused about getting the db.open() mechanism just right, if I use db.open(), and since it’s a stream, it complains that it can’t open it multiple times. If I remove it, it says it can’t find an open connection. How do I open the connection one time to allow storing of the stream?

I instantiate mongo with:

mongo = require('mongodb'),
    db = new mongo.Db('wikis', new mongo.Server('localhost', 27017, {}), {});

the stream kicks out an object like this:

return {
    flag: flag,
    page: page,
    pageUrl: pageUrl,
    url: m[3],
    delta: delta,
    comment: m[6],
    wikipedia: wikipedia,
    wikipediaUrl: wikipediaUrl,
    wikipediaShort: config.wikipedias[msg[0]].short,
    wikipediaLong: config.wikipedias[msg[0]].long,
    user: user,
    userUrl: userUrl,
    unpatrolled: isUnpatrolled,
    anonymous: anonymous,
    robot: isRobot,
    namespace: namespace,
    minor: isMinor

}

And I want to store parts of the stream like this:

function saveRecs(msg){
//db.open(function(){

    db.collection('wikiCollection', function(err, collection){
        doc = {
            "page": msg.page,
            "url": msg.url,
            "user": msg.user
        };

        collection.insert(doc, function(){
            console.log('Got a record, boss!');
        }); 
    });
//});
}
  • 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-04T07:03:55+00:00Added an answer on June 4, 2026 at 7:03 am

    The db.open takes a callback like this

    dbOpenCallback(err, db){
      // Check if err is set to anything other wise you are good
    }
    //...
    db.open(dbOpenCallback);
    

    Once you have established the connection is open and ok to go, your saveRecs function will be ok to call as long as the db variable is in scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the ajaxify-html5.js script found here: https://github.com/browserstate/ajaxify The script is working great, except
I have been working with the google docs api found here: https://developers.google.com/google-apps/documents-list/#introduction This issue
This script is working here https://jsfiddle.net/ByEzF/ but in the site that stopping working: <script
I'm trying to update some existing code that normally runs a Perl script which
My working code here correctly put the Tweet button on the page and allows
This is a duplicate of https://serverfault.com/questions/102098/powershell-script-showing-commands-run . I thought it would be more appropriate
My friend gave the following code which is working awesome here http://jsfiddle.net/WVLE2/ I tried
I'm trying to write a bot for turntable.fm using alaingilbert's API (https://github.com/alaingilbert/Turntable-API), which uses
My Facebook connect stopped working on TopTopGames.com for some reason. I have no idea
Here is my working example trying to load a file from github: <html> <head><title>Get

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.