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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:21:32+00:00 2026-06-14T18:21:32+00:00

I am trying to use node.js to provide json results from MongoDB. var http

  • 0

I am trying to use node.js to provide json results from MongoDB.

var http = require('http');
var mongo = require('mongoskin');

http.createServer(function (req, res) {
  var args = req.url.split("/");
  console.log(args);
  var searchCollection = args[1];
  var searchVar = args[2];
  var searchString = args[3];
  var conn = mongo.db('user:pass@alex.mongohq.com:10039/name',{safe:true});
  conn.collection(searchCollection).find({searchVar:searchString}).toArray(function(err, items){
    if(err) throw err;
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end(JSON.stringify(items));
  });
}).listen(process.env.PORT, process.env.IP);

The problem I am having is when I call the find function on the database it:-

  • searches for a document with a variable ‘searchVar’
  • rather than searching for a variable with the value of the searchVar

Any help would be appreciated. Thanks!

  • 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-14T18:21:33+00:00Added an answer on June 14, 2026 at 6:21 pm

    You will need to create your query object something like this:

    var query = {};
    query[searchVar] = searchString;
    

    And then pass this into your query:

      conn.collection(searchCollection).find(query).toArray(function(err, items){
        if(err) throw err;
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end(JSON.stringify(items));
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use node.js with mongodb and following the tutorial at http://howtonode.org/express-mongodb
I'm trying to use Node.js to create a zip file from an existing folder,
I'm trying to use quoted text in one of node's attributes: var network_json =
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to learn how to use Node, Mongoose, and Mongo by looking
At the moment I'm trying to use node-sftp in order to provide my nodejs
I'm trying to compile LESS from PHP and don't want to use node.js or
I'm trying to use jasmine-node for our testing of js files. We've written some
This is the provided function template I'm trying to use: template <class Process, class
So I'm trying to use the Node class that I just wrote in my

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.