Mongo and operators
Giedrius Baronas
g.baronas at gmail.com
Tue Mar 30 00:39:32 CEST 2021
Hi,
I tried different queries but they are failed.
What should be the result of the query so that there is no error message?
[ { attribute: 'User-Name', value: 'test', op: ':=' },
{ attribute: 'User-Password', value: '12345', op: ':=' } ]
OR
[ { 'test', attribute: 'User-Password', value: '12345', op: ':=' } ]
OR
[ { 'User-Name', value: 'test', attribute: 'User-Password', value:
'12345', op: ':=' } ]
On raddb/mods-config/sql/main/mongo/queries.conf examples I see
# Example of Result:
#
# { "attribute" : "User-Name", "Value" : "pippo", "op" : ":=" }
# { "attribute" : "ClearText-Password", "value" : "pwd1", "op" : ":=" }
# { "attribute" : "Cache-TTL", "value" : 1000, "op" : ":=" }
My query
db.radcheck.aggregate([
{
'$match': {
'User-Name': 'test'
}
}, {
'$addFields': {
'attributes.User-Name': '$User-Name',
'attributes.User-Password': '$User-Password'
}
}, {
'$project': {
'_id': 0,
'attributes': {
'$objectToArray': '$attributes'
}
}
}, {
'$unwind': {
'path': '$attributes'
}
}, {
'$project': {
'_id': 0,
'attribute': '$attributes.k',
'value': '$attributes.v',
'op': ':='
}
}
])
My result on mongoDB Compass
[ { attribute: 'User-Name', value: 'test', op: ':=' },
{ attribute: 'User-Password', value: '12345', op: ':=' } ]
My error on FreeRadius
getting result from row 0 = 0x5639efc55b90
(0) sql: ERROR: The op field for attribute 'test = (null)' is NULL, or
non-existent.
(0) sql: ERROR: You MUST FIX THIS if you want the configuration to
behave as you expect
(0) sql: ERROR: Value field is empty or NULL, skipping the entire row
(0) sql: ERROR: Error parsing user data from database result
(0) sql: ERROR: Error getting check attributes
Giedrius
On 2021-03-24 14:36, Alan DeKok wrote:
> On Mar 23, 2021, at 8:40 PM, Giedrius Baronas <g.baronas at gmail.com> wrote:
>> (0) sql: ERROR: The op field for attribute ':= = (null)' is NULL, or non-existent.
> That's telling.
>
> The operator name here is ":=". The value is NULL. This says that you're returning the fields in the wrong order.
>
> See raddb/mods-config/sql/main/mongo/queries.conf
>
> # These queries compare the check items for the user
> # in ${authcheck_table} and setup the reply items in
> # ${authreply_table}. You can use any query/tables
> # you want, but the return data for each row MUST
> # be in the following order:
> #
> # 0. Row ID (currently unused)
> # 1. UserName/GroupName
> # 2. Item Attr Name
> # 3. Item Attr Value
> # 4. Item Attr Operation
>
> Alan DeKok.
>
>
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
More information about the Freeradius-Users
mailing list