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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:42:08+00:00 2026-06-14T04:42:08+00:00

db.foo.find(); _id | type ————- 10001 1 10002 ‘a’ 10003 [1, 2, 3, 4]

  • 0
db.foo.find();


_id    | type
-------------
10001     1
10002    'a'
10003    [1, 2, 3, 4]

As you know, the $type will match the type code in mongo query, like this:

db.foo.find({type: {$type: 4}});

_id | type

———-

10003, [1, 2, 3, 4]

and then, I write a javascript shell script called test.js

var curs = db.foo.find();
curs.forEach(showTypeCode);
function showTypeCode(cur) {
  print(cur.type + '-' + typeof(cur.type));
};

results:

1-number
a-string
1,2,3,4-object (this is an array, it's 4 in mongo)

here is my question, how can I get the array type code in the mongo shell

  • 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-14T04:42:09+00:00Added an answer on June 14, 2026 at 4:42 am

    Your first query of:

    db.foo.find({type: {$type: 4}});
    

    Will not actually work due to a bug. This is a known bug within MongoDB whereby it reads an array as an object when using the $type operator. You can vote and put your support to this JIRA: https://jira.mongodb.org/browse/SERVER-1475

    As for solving the issue with the JS, this question might be of help to you: Detect if parameter passed is an array? Javascript

    Arrays are Objects of the class Array so that is why you are getting object back. If you test for an instance of Array then it should work.

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

Sidebar

Related Questions

This code $html = file_get_html('http://runkeeper.com/user/'.RUNKEEPER_ID.'/activity/'); $link1 = $html->find('.activityMonth', 0); will return the FIRST (foo,
I find the following example mildly surprising: >>> class Foo: def blah(self): pass >>>
currently I'm trying to find a regular expression with the following condition: Match: FOO_.*
I am looping through ArrayList<Bar> . Foo extends Bar . I'm trying to find
foo\r\nbar.replace(/(foo).+/m, bar) Hello. I can not understand why this code does not replace foo
I've created a new node type that is identical to a page called foo,
When foo method of MyController is called via Ajax, it may return Javascript code
I noticed (and verified in the sunspot code) the following behavior class Foo <
I read PEP 8: Style Guide for Python code , but I couldn't find
#foo {width: 300px; height: 400px; overflow: hidden;} <div id=foo></div> this.someimage = randomImageUrl; $(foo).innerHTML =

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.