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

  • Home
  • SEARCH
  • 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 8034447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:01:03+00:00 2026-06-05T02:01:03+00:00

I am using the Node.js driver for MongoDB and have no trouble constructing query

  • 0

I am using the Node.js driver for MongoDB and have no trouble constructing query objects outside of the call to find() until I attempt to introduce an $or construct into the mix.

I am attempting to dynamically generate the query because I have a variable number of parameters and would prefer to NOT have as many calls to collection.find as I have parameters.

To that end I am using a query as simple as:

var query = {};
query['name'] = 'Steve';
query['date_created'] = '<some date>';

mongo_collection.find(query, function(err, c) {});

However, when I attempt to use $or the whole process falls apart.

I have tried each of the following with no joy:

var query = {};

1.

query[$or] = [ { 'field' : 'value1' }, { 'field' : 'value2' } ];
query['date_created'] = '<some date>';

2.

query = { $or : [ { 'field' : 'value1' }, { 'field' : 'value2' } ] };
query['date_created'] = '<some date>';

3.

query = eval("[ { 'field' : 'value1' }, { 'field' : 'value2' } ]");
query['date_created'] = '<some date>';

In every case the $or is wrapped in quotes (honestly I am not sure if this is the problem or not…) and the query fails.

Is there any way to accomplish this?

  • 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-05T02:01:05+00:00Added an answer on June 5, 2026 at 2:01 am

    Here is how you can do it (there are probably multiple ways):

    var query = {};
    
    query["$or"]=[];
    query["$or"].push({"field":"value1"});
    query["$or"].push({"field":"value2"});
    query["date_created"]="whatever";
    
    query
    {
        "$or" : [
            {
                "field" : "value1"
            },
            {
                "field" : "value2"
            }
        ],
        "date_created" : "whatever"
    }
    

    Now you should be able to run db.collection.find(query)

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

Sidebar

Related Questions

Im using the npm mongodb driver with node. I have collection.findOne({query}, function(err, result) {
I am using nodejs and the node-mysql driver. I find myself doing repetitive boiler
I am new to Node, and I'm using Mongoose as a driver for MongoDB.
I am currently playing around with node.js and MongoDB using the node-mongo-native driver. I
I am writing some node.js code using the node-mongodb driver. I decided to cache
I just wrote my first nodejs program using the node-mongodb-native driver. I used the
Can you save nested objects in redis? I'm using the node.js driver. One of
I'm using Node.js and I want to see all of the parameters that have
I am using node and express. To register a controller I call: app.get('/user/:id', function
I am using node.js with express. I read out data from MongoDB with Mongoose

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.