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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:38:15+00:00 2026-06-12T14:38:15+00:00

Take inner array of mongo document using with limit and skip in php. $db->users->findOne(array(‘_id’

  • 0

Take inner array of mongo document using with limit and skip in php.

$db->users->findOne(array('_id' => new MongoId('5045fa0213cfcdfc06000008')));

Above query will give me below mongo array

[_id] => MongoId Object (
    [$id] => 5045fa0213cfcdfc06000008
)
[items] => Array (
    [0] => 13
    [1] => 4
    [2] => 3
    [3] => 7
    [4] => 10
    [5] => 11
    [6] => 28
    [7] => 54
    [8] => 31
    [9] => 33
    [10] => 37
    [11] => 12
)

Is it possible to make use of limit with skip with above mongo doc, something like below

$db->users->
  findOne(array('_id' => new MongoId('5045fa0213cfcdfc06000008')))->
    limit(5)->skip(5);

Which will output as

[_id] => MongoId Object (
    [$id] => 5045fa0213cfcdfc06000008
)
[items] => Array (
    [5] => 11
    [6] => 28
    [7] => 54
    [8] => 31
    [9] => 33
)

And how to take total count of items array using mongo?

  • 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-12T14:38:16+00:00Added an answer on June 12, 2026 at 2:38 pm

    The limit() and skip() methods only apply at the document level, not the array level.

    You can use the $slice operator to fetch a subset of an array:

    $skip = 5;
    $limit = 5;
    
    $filter = array('_id' => new MongoId('5045fa0213cfcdfc06000008'));
    $slice = array('items' => array( '$slice' => array( $skip, $limit ) ));
    
    $db->users->findOne($filter, $slice);
    

    There currently (as at MongoDB 2.2.0) isn’t a straightforward way to determine the size of the array without fetching it. You could do some manipulation using the new Aggregation Framework but that’s perhaps overkill.

    A common usage pattern is to use $inc to adjust a counter in a document in the same update when items are added or removed from an array.

    And how to take total count of items array using mongo?

    Here is a quick example using the Aggregation Framework in the mongo shell:

    db.users.aggregate(
        { $unwind: '$items' },
        { $group: {
            '_id': '$_id',
            itemcount: { $sum: 1 }
        }}
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which Transaction does the inner TransactionScope take as ambient transaction ? using ( var
Please take a look at this simple code: http://jsfiddle.net/kerp3/ The box has an inner
am new to lex and I wanna take all the matches specific to a
Little problem about sending PHP array to javascript function, i did homework looked everywhere
Take a look at the following mySQL query: SELECT fname,lname FROM users WHERE users.id
Take a look a this . I'm accessing the button's height and width using
Fiddle I can of course take the .inner layer out of .main layer and
I have the below sql, which if i take out the inner join to
Take a look at this example here: http://denise.brixwork.com/showlisting/1/8297-Valley-Drive-Alpine-Meadows-Whistler-denise-brown-real-estate And the red tables under Specifications
Take a basic function fun<-function(){ x<-c(1,2,3,4,5) y<-c(1,2,3,4,5) t<-x+y return(t) } After I have run

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.