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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:57:22+00:00 2026-05-21T09:57:22+00:00

I use following document schema: //User Document { _id: 0610457c-b25b-4e73-b859-11987a3fe271, FirstName: Some Name, LastName:

  • 0

I use following document schema:

//User Document
 {
     "_id": "0610457c-b25b-4e73-b859-11987a3fe271",
     "FirstName": "Some Name",
     "LastName": "surname",
     // it is array of ledger items
     "LedgerBook": [
            {
                "AccountId": "aadfgdf6319d3-1a12-4575-9776-c6653sdfg5c32527",
                "TransactionId": "ef98bbc4-3efb-46dc-b632-5adfgdfg1fcc378446",
                ....
            },
            ... 
      ]

and when I try to apply query db.users.find({ "LedgerBook" : { "$type" : 4 } }).limit(50); it returns nothing, but for query db.users.find({ "LedgerBook" : { "$type" : 3 } }).limit(50); works well(return all documents that has LedgerBook items).

Why does it happen?

type = 4 is Array and type = 3 is Object.

I want to get all documents thats have at least one LedgerBook item.

  • 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-21T09:57:22+00:00Added an answer on May 21, 2026 at 9:57 am

    When you query against an array the test is conceptually applied to each element of the array until it returns true for one of the elements, or until the end of the array is reached.

    So the query:

    db.items.find({ LedgerBook : { $type : 4 }})
    

    actually means: find all documents where at least one of the items of the LedgerBook array is itself an array. Even though LedgerBook itself is an array, none of its elements are, so no documents match the query.

    If you just want to query for documents that have a LedgerBook element you can use:

    db.items.find({ LedgerBook : { $exists : true }})
    
    • 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 Apache mod_rewrite to achieve the following: In the document
I use the following XmlSchema: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema targetNamespace=http://www.test.com/XmlValidation elementFormDefault=qualified attributeFormDefault=unqualified xmlns:m=http://www.test.com/XmlValidation>
For the following XML <Properties ComponentID=1272040480745 Admin=true> <Datum ID=P01 Type=File Name=CSS To Use>style.css</Datum> <Data>
I've got the following simple XSD document ( foo.xsd ): <?xml version=1.0 encoding=UTF-8?> <xsd:schema
Appreciate some insight given the following code: <script type=text/javascript> $(document).ready(function() { var soapEnv =
I use following style attribute so when i will start typing in text box
I use following code: Create a retry policy, when error, retry after 1 second,
I just use following code to add an image to my project, var paper
When i use following: var child:DisplayObjectContainer = dso.getChildAt( dso.numChildren -1 ) as DisplayObjectContainer; trace(child);
for example i use following command to find a record SELECT `users`.`mail` FROM `users`

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.