[SERVER-27752] How to add field with static value to mongodb find query? Created: 19/Jan/17  Updated: 20/Jan/17  Resolved: 20/Jan/17

Status: Closed
Project: Core Server
Component/s: Logging, Querying
Affects Version/s: 3.2.9
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Sanjeev Kumar Assignee: Mark Agarunov
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Can we add some custom field with static value to mongodb find query?

I am trying to add/append API request UId to all the queries that we are making to mongodb, so that we can map requests with slow queries from mongodb logs.

I am doing it in aggregate queries by using '$literal' in projected fields.
My Aggregate queries looks something like :

db.test.aggregate({
        $project: {
            "custom_id": { $literal: "uid" } 
            ..
        }
        ..
    })

Also I can't include each field individually in projected fields and add the "custom_id" field with the static value.



 Comments   
Comment by Sanjeev Kumar [ 20/Jan/17 ]

Hi,

Thanks for the reply.
The $comment operator is exactly what I was looking for.
I will be mindful about not posting any such queries here in future.

Thanks,
Sanjeev

Comment by Mark Agarunov [ 19/Jan/17 ]

Hello sanjeev24,

Thanks for your report. It seems that your goal is to add a value to all of your queries. If this is the case, the $comment operator, for which documentation can be found here, is likely the best way to accomplish this.

Please note that 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. A question like this involving more discussion would be best posted on the mongodb-user group.

Thanks,
Mark

Generated at Thu Feb 08 04:16:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.