Generate Code for Shell and C# feature is buggy

Ervs Sevilla shared this problem 17 months ago
Solved

My mongo shell script:


db.test.aggregate(

{ $match: { $and: [ {isActive: {$eq: true} }, { id: {$eq: '4011caa5-6d09-4a3a-83e1-ca70c9b65457'}}] }},

{ $unwind: { path: '$departmentDegrees'} },

{ $match : {'departmentDegrees.isActive': { $eq : true} }},

{

$project: {

_id: 1, id:1, doctype:1, idSchl:1, schoolName:1, _idAcademicLevel:1, academicLevel:1,

isActive:1, updatedOn:1, aeBy:1, sysDate:1,

"departmentDegrees._idDeptDegree":1, "departmentDegrees._idDeptInfo":1,

"departmentDegrees.deptName":1, "departmentDegrees.deptShortName":1, "departmentDegrees.isActive":1,

"departmentDegrees.majors": {

$filter: {

input: "$departmentDegrees.majors",

as: "mj",

cond: { $eq: [ "$$mj.isActive", true ] }

}

},

"departmentDegrees.minors": {

$filter: {

input: "$departmentDegrees.minors",

as: "m",

cond: { $eq: [ "$$m.isActive", true ] }

}

}

}

},

{

$group: {

_id : {

_id: "$_id", id: "$id", doctype: "$doctype", idSchl: "$idSchl",

schoolName: "$schoolName", _idAcademicLevel: "$_idAcademicLevel", academicLevel: "$academicLevel",

isActive: "$isActive", updatedOn: "$updatedOn", aeBy: "$aeBy", sysDate: "$sysDate"

}

,departmentDegrees1: {

"$addToSet" : "$departmentDegrees"

}

}

},

{

$project: {

_id: "$_id._id", id: "$_id.id", doctype: "$_id.doctype", idSchl: "$_id.idSchl",

schoolName: "$_id.schoolName", _idAcademicLevel: "$_id._idAcademicLevel", academicLevel: "$_id.academicLevel",

isActive: "$_id.isActive", updatedOn: "$_id.updatedOn", aeBy: "$_id.aeBy", sysDate: "$_id.sysDate",

departmentDegrees1: "$departmentDegrees1"

}

}

)


NoSQLBooster Generated Code for C#: This returns completely different result sets.


var pipeline = new[]{new BsonDocument(){

{"$match", new BsonDocument(){

{"$and", new BsonArray(){new BsonDocument(){

{"isActive", new BsonDocument(){

{"$eq", true}

}}

},new BsonDocument(){

{"id", new BsonDocument(){

{"$eq", "4011caa5-6d09-4a3a-83e1-ca70c9b65457"}

}}

}}},

{"departmentDegrees.isActive", new BsonDocument(){

{"$eq", true}

}}

}}

},new BsonDocument(){

{"$unwind", new BsonDocument(){

{"path", "$departmentDegrees"}

}}

},new BsonDocument(){

{"$project", new BsonDocument(){

{"_id", "$_id._id"},

{"id", "$_id.id"},

{"doctype", "$_id.doctype"},

{"idSchl", "$_id.idSchl"},

{"schoolName", "$_id.schoolName"},

{"_idAcademicLevel", "$_id._idAcademicLevel"},

{"academicLevel", "$_id.academicLevel"},

{"isActive", "$_id.isActive"},

{"updatedOn", "$_id.updatedOn"},

{"aeBy", "$_id.aeBy"},

{"sysDate", "$_id.sysDate"},

{"departmentDegrees._idDeptDegree", 1},

{"departmentDegrees._idDeptInfo", 1},

{"departmentDegrees.deptName", 1},

{"departmentDegrees.deptShortName", 1},

{"departmentDegrees.isActive", 1},

{"departmentDegrees.majors", new BsonDocument(){

{"$filter", new BsonDocument(){

{"input", "$departmentDegrees.majors"},

{"as", "mj"},

{"cond", new BsonDocument(){

{"$eq", new BsonArray(){"$$mj.isActive",true}}

}}

}}

}},

{"departmentDegrees.minors", new BsonDocument(){

{"$filter", new BsonDocument(){

{"input", "$departmentDegrees.minors"},

{"as", "m"},

{"cond", new BsonDocument(){

{"$eq", new BsonArray(){"$$m.isActive",true}}

}}

}}

}},

{"departmentDegrees1", "$departmentDegrees1"}

}}

},new BsonDocument(){

{"$group", new BsonDocument(){

{"_id", new BsonDocument(){

{"_id", "$_id"},

{"id", "$id"},

{"doctype", "$doctype"},

{"idSchl", "$idSchl"},

{"schoolName", "$schoolName"},

{"_idAcademicLevel", "$_idAcademicLevel"},

{"academicLevel", "$academicLevel"},

{"isActive", "$isActive"},

{"updatedOn", "$updatedOn"},

{"aeBy", "$aeBy"},

{"sysDate", "$sysDate"}

}},

{"departmentDegrees1", new BsonDocument(){

{"$addToSet", "$departmentDegrees"}

}}

}}

}};


NoSQLBooster Generated Code for Shell: This returns completely different result sets.


db.test.aggregate([{

$match: {

$and: [{

isActive: {

$eq: true

}

}, {

id: {

$eq: "4011caa5-6d09-4a3a-83e1-ca70c9b65457"

}

}],

"departmentDegrees.isActive": {

$eq: true

}

}

}, {

$unwind: {

path: "$departmentDegrees"

}

}, {

$project: {

_id: "$_id._id",

id: "$_id.id",

doctype: "$_id.doctype",

idSchl: "$_id.idSchl",

schoolName: "$_id.schoolName",

_idAcademicLevel: "$_id._idAcademicLevel",

academicLevel: "$_id.academicLevel",

isActive: "$_id.isActive",

updatedOn: "$_id.updatedOn",

aeBy: "$_id.aeBy",

sysDate: "$_id.sysDate",

"departmentDegrees._idDeptDegree": 1,

"departmentDegrees._idDeptInfo": 1,

"departmentDegrees.deptName": 1,

"departmentDegrees.deptShortName": 1,

"departmentDegrees.isActive": 1,

"departmentDegrees.majors": {

$filter: {

input: "$departmentDegrees.majors",

as: "mj",

cond: {

$eq: ["$$mj.isActive", true]

}

}

},

"departmentDegrees.minors": {

$filter: {

input: "$departmentDegrees.minors",

as: "m",

cond: {

$eq: ["$$m.isActive", true]

}

}

},

departmentDegrees1: "$departmentDegrees1"

}

}, {

$group: {

_id: {

_id: "$_id",

id: "$id",

doctype: "$doctype",

idSchl: "$idSchl",

schoolName: "$schoolName",

_idAcademicLevel: "$_idAcademicLevel",

academicLevel: "$academicLevel",

isActive: "$isActive",

updatedOn: "$updatedOn",

aeBy: "$aeBy",

sysDate: "$sysDate"

},

departmentDegrees1: {

$addToSet: "$departmentDegrees"

}

}

Comments (4)

photo
1

Thank you for your feedback. It's bug . At present, we are now in vocation of Chinese Spring Festival. We may not response to this issue in time.

We will work out a hot fix to resolve it as soon as possible.

photo
1

Thank you sir.....

By the way - heres a sample of my document.

{

"_id" : ObjectId("5a7a9e0f8830e32514b15066"),

"id" : "4011caa5-6d09-4a3a-83e1-ca70c9b65457",

"doctype" : "FieldStudy",

"idSchl" : "ec68b42b-0676-4087-ba14-37a9f2d40b41",

"schoolName" : "Testing 17",

"_idAcademicLevel" : "7c8d5e75-f86a-43bb-9170-d2667d0492ed",

"academicLevel" : "College",

"departmentDegrees" : [

{

"_idDeptDegree" : "eba29dae-447f-4cdd-8ba7-034a03c53f94",

"_idDeptInfo" : "1ec90940-3f15-41d0-89cd-ae862b8ff28d",

"deptName" : "Computer Science",

"deptShortName" : "CompSci",

"majors" : [

{

"_idMajor" : "7f09990b-fd77-49d0-bbac-8e4048a93df6",

"degree" : "Bachelor of Science - B.S.",

"major" : "Computer Science in Software Track",

"majorShort" : "CompSci Software",

"numYrs" : "4",

"totalUnits" : "121",

"isActive" : false

},

{

"_idMajor" : "4a5f02d8-1347-4b57-ab74-897557be5a96",

"degree" : "Bachelor of Science - B.S.",

"major" : "Computer Science in Hardware",

"majorShort" : "CompSci Hardware",

"numYrs" : "4",

"totalUnits" : "131",

"isActive" : true

}

],

"minors" : [

{

"_idMinor" : "ba1d3432-eea7-4cfa-9ddf-67ad4e416483",

"minor" : "Computer Science",

"minorShort" : "CompSci",

"totalUnits" : "20",

"isActive" : true

}

],

"isActive" : true

}

],

"isActive" : true,

"updatedOn" : null,

"aeBy" : "esevilla",

"sysDate" : ISODate("2018-02-06T22:34:55.253-08:00")

}

photo
1

thank you sir...

I tested the shell version but not the C# and it works!