0

I have array of _id's like

arr=["xxxx","yyyyy",zzzz"]

NOw I want to return all the docs of these ids from a collection like

coll.find({_id:{$in:{arr}})//must return xxx.yyy.zzz docs

this is returning all fields from collection, How to do this?

these are my docs

  {_id:"xxx",
         bvalue:"val",
         cval:"val"
    }
     {_id:"yyy",
         bvalue:"val",
         cval:"val"
    }
     {_id:"zzz",
         bvalue:"val",
         cval:"val"
    }

I need a query which returns all documents with id's in array In my array I have id's xxx,yyy,zzz so I want all these docs to return

2
  • 1
    Re-phrase the question and give an example. Commented Sep 30, 2014 at 9:33
  • 1
    Please add your doc structure Commented Sep 30, 2014 at 10:09

1 Answer 1

2

The query is doing exactly what it is supposed to - returning the documents that match your query criteria. If you just want the _id's back, use projection:

db.coll.find({ "_id" : { "$in" : arr }, { "_id" : 1 })
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.