0

I have queried mongodb by using aggregate function and got two fields in the output. The result of my db.Collection.aggregate(..) looks like the below:

{ 
  "_id" : NumberLong(203440), 
  "date" : ISODate("2013-05-11T00:00:00Z")
}
{ 
  "_id" : NumberLong(203520), 
  "date" :ISODate("2013-01-05T00:00:00Z") 
} 
{ 
  "_id" : NumberLong(203970),
  "date": ISODate("2013-01-11T00:00:00Z") 
} 
{ 
  "_id" : NumberLong(203660),
  "date" : ISODate("2013-01-11T00:00:00Z")
} 
{ 
  "_id" : NumberLong(203360), 
  "date" : ISODate("2013-01-11T00:00:00Z")
}

How do I get the records in the collection for which these two fields are true?(in a single query)

i.e If each record in my collection has the fields data,_id, x, y, z, a , b and c, how do I fetch list of records for which the date and _id are equal to the above result of aggregate?

2
  • The value in the aggregation result "_id" is actually the field x in the document. Commented Sep 7, 2015 at 2:23
  • Please show the original document and the aggregation pipeline you have tried so far. Commented Sep 7, 2015 at 2:26

1 Answer 1

0

In the aggregation command, using the below in the $group part helped me.

"allFields": { "$first": "$$CURRENT" }

In my response, I got the entire document in "allFields" field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.