Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions