hello,
I am trying to create a MongoDB view on a collection, and use the resulting view as a EVE resource.
So, when starting, up I do the following in order to create a dynamic mongo view, that aggregates my documents in the "entities" collection according to their "type" and creates another dynamic collection called "agglomerate":
mongo = app.data.driver
with app.app_context():
mongo.db.drop_collection("agglomerati")
mongo.db.create_collection(
'agglomerate',
viewOn='entities',
pipeline=[
{"$group" : {
"_id":"$type",
"count":{"$sum" : 1}
}},
]
)
Then I create a GET resource in EVE, attached to that datasource:
agglomerati_datasource_properties = {
# this endpoint targets a mongodb view (created outside of EVE)
'source': 'agglomerate',
}
agglomerati_endpoint = {
'url': "agglomerate",
'resource_methods': ['GET'],
'datasource': agglomerati_datasource_properties,
}
DOMAIN = {
'dummy5': agglomerati_endpoint,
}
BUT, when i fetch from /agglomerate, what I get is:
{
"_items": [
{
"_id": "temperature",
"_created": "Thu, 01 Jan 1970 00:00:00 GMT",
"_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
"_etag": "9d2f5fe13f81e7b9dae40b45f7c441a80b1b64a8"
},
{
"_id": "Vehicle",
"_created": "Thu, 01 Jan 1970 00:00:00 GMT",
"_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
"_etag": "fae6650659a56aca57bdd8e777b267877dfe9d2a"
}
],
"_meta": {
"page": 1,
"max_results": 25,
"total": 2
}
}
As you can see, the "count" field is missing, and there are _etag, _created, _updated auto-generated fields with some zero zero Unix date.
Additionally, I confirm with MongoDB Atlas that the view properly contains the "count" field.
Whatever other field I add in the pipeline that feeds the view, it does not show up in the response to the GET. (And it is there in the DB).
The only fields that ever show up are: _id, _etag; _created, _updated.
Any help, clues, suggestions?
Tnx
giuseppe