[SERVER-15918] Unable to create field with update which is calculated with size array. Created: 03/Nov/14  Updated: 03/Dec/14  Resolved: 03/Dec/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.4
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: GERVAIS Mickaël Assignee: Ramon Fernandez Marina
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-11345 Allow update to compute expressions u... Closed
Participants:

 Description   

Hi,

I've a document which contains an array of nested object.
I need to have the global sum of the size of array.
I've written an agrgegation:

db.values.aggregate( 
    [
        {$group : 	{
                        _id     : null , 
                     	count	:   { 
                                        $sum: {$size : '$markers'}
                                    }
                                }
    ])

My collection contains 2610537 documents, so the query is very long. (Too long for me)

I think it will be quicker to have an intermadiate field with the markers size. But I cannot write the update query:

db.values.update(
    { 'sample' : 1753068}, // Used to reduce documents and test.
    { 
        '$set': {
            'count': { $size : markers}
        } 
    },
    {
        upsert : false
    }
)

This give me this error:
ReferenceError: markers is not defined (shell):5

But 'markers' is my arrays of nested objects. so this field exist.

After reading the doc, $size is not part of update operators...

Is there a way to handle this case? (I know , I can do this on update or insert process)

Thanks

Mickael



 Comments   
Comment by Ramon Fernandez Marina [ 03/Dec/14 ]

mgervais, a colleague points out there's already a ticket requesting a wider set of features like this one, so I'm going to mark this ticket as a duplicate of SERVER-11345. Please feel free to comment and/or vote for SERVER-11345.

Regards,
Ramón.

Comment by Asya Kamsky [ 07/Nov/14 ]

That seems to be an improvement similar or identical to SERVER-11345 request.

Comment by GERVAIS Mickaël [ 04/Nov/14 ]

Hi,

Excuse me for the bad post location.

I'll move this question, but I think this is a king of improvement for update operators.

Thanks for your response.

Mickael

Comment by Ramon Fernandez Marina [ 03/Nov/14 ]

Thanks for your report @mgervais. Note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group.

Regards,
Ramón.

Generated at Thu Feb 08 03:39:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.