How to compare a field with another in Mongodb aggregation? -


I have several levels in the pipeline, now I would like to compare two areas as follows:

  db.collection.aggregate ({...}, {$ match: {firstfield: {$ gte: "$ secondfield"}}})   

How to write this question? Close, but the actual greeting is slightly different:

 {code> db.collection.aggregate ({{" first project ": {" firstfield ": 1," secondfield ": 1," difference ": {" $ gte ": [" $ firstfield " , "$ secondfield"]}}}, {"$ match": {"difference": true}}]   

for a slightly different invitation, (or possibly) On field comparison, a true | False the value can be returned.

This allows you to filter later with the phase Pipeline to present the "Include Include" results depending on the logical state.

Comments

Popular posts from this blog

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

sql - PostgreSQL automatically update row at specific date -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -