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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:49:21+00:00 2026-05-28T04:49:21+00:00

I have a collection with a subdocument tags like : Collection News : title

  • 0

I have a collection with a subdocument tags like :

Collection News :
   title (string)
   tags: [tag1, tag2...]

I want to select all the tags who start with a pattern, but returning only the matching tags.

I already use a regex but it returns all the news containing the matching tag, here is the query :

db.news.find( {"tags":/^proga/i}, ["tags"] ).sort( {"tags":1} ).
    limit( 0 ).skip( 0 )

My question is : How can I retrieve all the tags (only) who match the pattern ?
(The final goal is to make an autocomplete field)

I also tried using distinct, but I didn’t find a way to make a distinct with a find, it always returning me all the tags 🙁

Thanks for your time

  • 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-05-28T04:49:22+00:00Added an answer on May 28, 2026 at 4:49 am

    Embedded documents are not collections. Look at your query: db.news.find will return documents from the news collection. tags is not a collection, and cannot be filtered.

    There is a feature request for this “virtual collection feature” (SERVER-142), but don’t expect to see this too soon, because it’s “planned but not scheduled”.

    You can do the filtering client-side, or move the tags to a separate collection. By retrieving only a subset of fields – only the tags field – this should be reasonably fast.

    Hint: Your regex uses the /i flag, which makes it impossible to use indexation. Your db strings should be case-normalized (e.g. all upper case)

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

Sidebar

Related Questions

I have a collection of objects to which I'd like to just add a
I have a collection of classes that I want to serialize out to an
I have a collection of Boost unit tests I want to run as a
I have collection of similar strings for example : string 1: Customer's first Name
I have collection of custom objects(assets) which I want to group with LINQ. Custom
I am developing web application where users have collection of tags. I need to
I have a Collection of items that I would like to display the Total
I have collection: class HashedData : IComparable { string key; public string Key {
I have collection of Questions as List. For each question I want to show
I have a collection of elements on my page, and I want to see

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.