Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Create Index on array
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tom Vo  
View profile  
 More options Sep 7 2012, 2:13 am
From: Tom Vo <tom...@nexcel.vn>
Date: Fri, 7 Sep 2012 13:13:09 +0700
Local: Fri, Sep 7 2012 2:13 am
Subject: Re: [mongodb-user] Re: Create Index on array

Dear Thomas
I'll consider as your suggestion.Thank you for your kindly.

On Fri, Sep 7, 2012 at 11:51 AM, Thomas Rueckstiess <

Thomas.Ruecksti...@10gen.com> wrote:
> Hi Tom,

> according to the documentation, "Queries cannot use indexes for the $size<http://docs.mongodb.org/manual/reference/operators/#_S_size>portion
> of a query".
> http://docs.mongodb.org/manual/reference/operator/size/

> In order to make a query on the number of documents in an array efficient,
> you could add a separate field 'numCapturedDates' to your schema and
> manually increase and decrease it when you add/remove elements to/from the
> array. An index on 'numCapturedDates' would then help you efficiently
> retrieve documents with a certain number of elements.

> Regards,
> Thomas

> On Friday, September 7, 2012 1:06:38 PM UTC+10, Tom Vo wrote:

>> Dear all
>> *I have collection Devices with data sample below.*
>> db.Devices.find()
>> {
>>         "_id" : NumberLong(1),
>>         "CapturedDate" : [
>>                 [
>>                         1,
>>                         ISODate("2012-05-10T02:07:50.**159Z")
>>                 ],
>>                 [
>>                         2,
>>                         ISODate("2012-05-09T12:31:50.**299Z")
>>                 ]
>>         ],
>>         "OSName" : "Windows",
>>         "DeviceType" : "Mobile"
>> }

>> {
>>         "_id" : NumberLong(2),
>>         "CapturedDate" : [
>>                 [
>>                         1,
>>                         ISODate("2012-04-10T06:59:50.**123Z")
>>                 ],
>>                 [
>>                         3,
>>                         ISODate("2012-12-09T12:06:50.**243Z")
>>                 ]
>>         ],
>>         "OSName" : "Iphone",
>>         "DeviceType" : "Mobile"
>> }
>> *I want to find size of "CapturedDate" great than 2, and this query run
>> slowly. **I try to create index on "CapturedDate" but performance not
>> improve. Please give me to your suggestion to solute this trouble.*

>> db.Devices.ensureIndex( { CapturedDate : 1 } )
>> db.Devices.find({"**CapturedDate":{$size:2}},{**
>> CapturedDate:1}).explain()
>> {
>>         "cursor" : "BasicCursor",
>>         "nscanned" : 1218300,
>>         "nscannedObjects" : 1218300,
>>         "n" : 73,
>>         "millis" : 21544,
>>         "nYields" : 0,
>>         "nChunkSkips" : 0,
>>         "isMultiKey" : false,
>>         "indexOnly" : false,
>>         "indexBounds" : {

>>         }
>> }

>> > db.Devices.find( { $where: "this.CapturedDate.length > 1" }
>> ).hint({CapturedDate : 1}).explain()
>> {
>>         "cursor" : "BtreeCursor CapturedDate_1",
>>         "nscanned" : 1218376,
>>         "nscannedObjects" : 1218376,
>>         "n" : 73,
>>         "millis" : 23276,
>>         "nYields" : 0,
>>         "nChunkSkips" : 0,
>>         "isMultiKey" : true,
>>         "indexOnly" : false,
>>         "indexBounds" : {
>>                 "CapturedDate" : [
>>                         [
>>                                 {
>>                                         "$minElement" : 1
>>                                 },
>>                                 {
>>                                         "$maxElement" : 1
>>                                 }
>>                         ]
>>                 ]
>>         }

>> *Thanks and Regards*
>> *Tom Vo*

>  --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

--

Thanks and Best Regards
Tom Vo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.