Skip to content
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

$size operator requires an array of 1 operand #358

Open
ledomi opened this issue Sep 20, 2018 · 0 comments
Open

$size operator requires an array of 1 operand #358

ledomi opened this issue Sep 20, 2018 · 0 comments

Comments

@ledomi
Copy link

ledomi commented Sep 20, 2018

Hi All,

I think that validation for aggregation with $size is invalid. Step by step:

Fongo version: 2.1.1

My collection:

[{
		"_id": 5b894357a0c84d5a5d221f25,
		"conferenceName": "myFirstConference",
		"startDate": 1535722327,
		"endDate": 1535722420,
		"participants": [{
				"name": "user1",
				"origin": "internal",
				"ip": "192.168.0.2"
			}, {
				"name": "user2",
				"origin": "external",
				"ip": "172.20.0.3"
			},{
				"name": "user3",
				"origin": "internal",
				"ip": "192.168.0.3"
			},
		]
	}
]

My mongo query that works is :

db.collection.aggregate([{
		"$project": {
			"conferenceName": 1,
			"startDate": 1,
			"endDate": 1,
			"internalUsersCount": {
				"$size": {
					"$filter": {
						"input": "$participants",
						"as": "part",
						"cond": {
							"$eq": ["$$part.origin", "internal"]
						}
					}
				}
			}
		}
	}])

In that case as an input we have a LinkedHasMap not List but parsing was implementet as below

class ProjectedSize 
.....
 private String parseOperand(Object value) {
      if (!(value instanceof String) && (!(value instanceof List) || ((List) value).size() != 1)) {
        errorResult(coll, 16020, "the " + keyword + " operator requires an array of 1 operand");
      }
}

But it doesn't work in fongo, Anybody can help ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant