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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:58:51+00:00 2026-06-09T14:58:51+00:00

Suppose I have a document like this: { tags: [‘a’, ‘b’] } I want

  • 0

Suppose I have a document like this:

{
  tags: ['a', 'b']
}

I want to find all documents that have only the tag a. My current query criteria is:

{
  tags: {
    $size: 1,
    $in: ['a']
  }
}

Is there a way to query using an equal operator?

  • 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-09T14:58:52+00:00Added an answer on June 9, 2026 at 2:58 pm

    Although queries on array fields implicitly check array values, you can also match the entire array. Consider the following example, which has a mix of strings and arrays of strings in the tags field:

    > db.foo.find()
    { "_id" : ObjectId("502943541f5b0d2bca9663a8"), "tags" : [ "a" ] }
    { "_id" : ObjectId("502943581f5b0d2bca9663a9"), "tags" : [ "a", "b" ] }
    { "_id" : ObjectId("5029435e1f5b0d2bca9663aa"), "tags" : [ [ "a" ] ] }
    { "_id" : ObjectId("502943641f5b0d2bca9663ab"), "tags" : [ [ "a" ], "b" ] }
    { "_id" : ObjectId("5029436c1f5b0d2bca9663ac"), "tags" : [ [ "a" ], [ "b" ] ] }
    { "_id" : ObjectId("502943a31f5b0d2bca9663ad"), "tags" : [ "a", [ "b" ] ] }
    

    Querying for "a" in tags will match any array that contains "a" alone or in part:

    > db.foo.find({tags: "a"})
    { "_id" : ObjectId("502943541f5b0d2bca9663a8"), "tags" : [ "a" ] }
    { "_id" : ObjectId("502943581f5b0d2bca9663a9"), "tags" : [ "a", "b" ] }
    { "_id" : ObjectId("502943a31f5b0d2bca9663ad"), "tags" : [ "a", [ "b" ] ] }
    

    Although not shown, if we had a tags field that was simply "a" (not an array, but the string value), it would certainly be matched as well.

    Querying for ["a"] in tags will match the documents containing only "a" in their tags field as well as any tags arrays containing the value ["a"] (i.e. nested array):

    > db.foo.find({tags: ["a"]})
    { "_id" : ObjectId("502943541f5b0d2bca9663a8"), "tags" : [ "a" ] }
    { "_id" : ObjectId("5029435e1f5b0d2bca9663aa"), "tags" : [ [ "a" ] ] }
    { "_id" : ObjectId("502943641f5b0d2bca9663ab"), "tags" : [ [ "a" ], "b" ] }
    { "_id" : ObjectId("5029436c1f5b0d2bca9663ac"), "tags" : [ [ "a" ], [ "b" ] ] }
    

    If you can safely assume your schema will only store strings in its tags array, this query might be more desirable than storing the array size in a separate field and adding that to your query criteria (also a viable solution, as Matt mentioned).

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

Sidebar

Related Questions

Suppose that I have a document like this, and I want to search for
Suppose I have an HTML document that looks like this: <html lang=en> ... </html>
So i have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <gesmes:Envelope
Suppose that I have a simple form in my page like this : <form
When parsing HTML document, how Nokogiri handle <br> tags? Suppose we have document that
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input
Suppose I have a vertical menu that is coded like this: <ul class=sub-menu> <li
Suppose i have an xml document like this XML File: <document> <educationalsection> educational details
Suppose, I have a js file which looks like this: $(document).ready(function() { // first
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //

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.