Skip to content

Projections should follow mongodb conventions more precisely. [DATAMONGO-757] #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Sep 20, 2013 · 2 comments
Assignees
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link

Thomas Darimont opened DATAMONGO-757 and commented

At present a projection of with the SD MongoDB Aggregation Framework support defined by:
project("a", "b").andInclude("c").andExclude("_id").toDBObject(Aggregation.DEFAULT_CONTEXT);

Will be rendered as:

{$project: { "a" : "$a" , "b" : "$b" , "c" : "$c" , "_id" : 0}}

But, in order to comply with the mongodb conventions, it should rather be rendered like:

{$project: {  a : 1 , b : 1, c :1, _id : 0 }}

Note that both projections produce the same result:

db.test.insert({_id:"1234", a:4711,b:{data:"foo"}, c:33, d:9});

Variant 1:

db.test.aggregate([{$project: { "a" : "$a" , "b" : "$b" , "c" : "$c" , "_id" : 0}}])

Output:

> db.test.aggregate([{$project: { "a" : "$a" , "b" : "$b" , "c" : "$c" , "_id" : 0}}])
{
	"result" : [
		{
			"a" : 4711,
			"b" : {
				"data" : "foo"
			},
			"c" : 33
		}
	],
	"ok" : 1
}

Variant 2:

db.test.aggregate([{$project: {  a : 1 , b : 1, c :1, _id : 0 }}])

Output:

> db.test.aggregate([{ $project : { _id : 0 , a : 1 , b : 1, c :1 }}])
{
	"result" : [
		{
			"a" : 4711,
			"b" : {
				"data" : "foo"
			},
			"c" : 33
		}
	],
	"ok" : 1
}

Issue Links:

  • DATAMONGO-788 Projection operations do not render synthetic fields properly

Backported to: 1.3.2 (Babbage SR1)

@spring-projects-issues
Copy link
Author

Thomas Darimont commented

Added PR: #76
Please revise

@spring-projects-issues
Copy link
Author

Thomas Darimont commented

Updated PR according to code review:
#76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants