‘collection.documents(keys)’ method takes array of keys as arguments and return all the documents associated with these keys. If a document is not exist with given key, then it is excluded from the result.
Let’s experiment it with example.
127.0.0.1:8529@abc_org> db.user.toArray()
[
{
"_key" : "17089",
"_id" : "user/17089",
"_rev" : "_cRe1GKq---",
"id" : 1,
"firstName" : "Sailu",
"lastName" : "Ptr",
"age" : 32
},
{
"_key" : "17091",
"_id" : "user/17091",
"_rev" : "_cRe1GKu---",
"id" : 2,
"firstName" : "Gopi",
"lastName" : "Battu",
"age" : 33
},
{
"_key" : "17093",
"_id" : "user/17093",
"_rev" : "_cRe1GKy---",
"id" : 3,
"firstName" : "Krishna",
"lastName" : "Gurram",
"age" : 32
},
{
"_key" : "17095",
"_id" : "user/17095",
"_rev" : "_cRe1H-6---",
"id" : 4,
"firstName" : "Venkat",
"lastName" : "Ptr",
"age" : 35
}
]
Example: Get all the documents with keys "17095", "17093", "18907".
127.0.0.1:8529@abc_org> db.user.documents(["17095", "17093", "18907"])
{
"documents" : [
{
"_key" : "17093",
"_id" : "user/17093",
"_rev" : "_cRe1GKy---",
"id" : 3,
"firstName" : "Krishna",
"lastName" : "Gurram",
"age" : 32
},
{
"_key" : "17095",
"_id" : "user/17095",
"_rev" : "_cRe1H-6---",
"id" : 4,
"firstName" : "Venkat",
"lastName" : "Ptr",
"age" : 35
}
]
}
No comments:
Post a Comment