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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:34:03+00:00 2026-06-02T21:34:03+00:00

I am using MongoDB to store information on coffees and I am having problems

  • 0

I am using MongoDB to store information on coffees and I am having problems with a query.

My document structure is:

{ _id: "Thailand Bok", tags: ["Strong", "Smooth", "Dark"] }

I am trying to create query that allows me to search either on the name or tags.

So given that a query string may be “Thailand Bok” or [“Strong”, “Smooth”] I want to search for requests that either contain the _id or each tag.

If I were thinking in SQL terms it may be something like this:

"WHERE `_id` like 'Not present%' OR ("Strong" IN `tags` AND "Smooth" IN `tags`)"

The query I have so far is:

{ 
    $or: [
      { _id: { $regex: '^Not present', '$options': 'i' } },
      { 
          $and: [ 
              { tags: 'Strong' }, 
              { tags: 'Smooth' } 
          ]
      }
    ]
}

edit: correct a mistake in the query and clarified that it should work either if the _id matches OR the tags match

  • 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-02T21:34:05+00:00Added an answer on June 2, 2026 at 9:34 pm

    $and is only supported in version MongoDB 2.0+ I was using 1.8.2

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

Sidebar

Related Questions

I am using mongodb to store information of users. I wanted to create a
I am using mongodb to store user's events, there's a document for every user,
Is there any tool to query MongoDB using SPARQL ? I store object using
I'm trying to retrieve a document stored in MongoDB using its _id of the
Me and my colleges are having second thoughts on using MongoDB to store al
Using MongoDB, I'm having trouble adding en element to an Array when the array
I'm using MongoDB to store user profiles, and now I want to use GridFS
For my case i am using MongoDB to store a whole bunch of products
I'm considering using MongoDb for a backing store for a WPF app that I'm
I'm using mongodb and I store datetime in my database in this way for

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.