i have following mongodb document:
{
"_id" : ObjectId("5592c0e6ea16e552ac90e169"),
-----------
"location" : {
"_id" : ObjectId("5592c17fc3ad8cbffa0e9778"),
"companyFieldId" : ObjectId("559140f1ea16e552ac90e058"),
"name" : "Location",
"alias" : "Points",
"locations" : [
{
"_id" : ObjectId("5592c17fc3ad8cbffa0e9779"),
"country" : "India",
"state" : "Punjab",
"city" : "Moga",
"zip" : "142001",
"custom" : false
},
{
"_id" : ObjectId("5592c17fc3ad8cbffa0e977a"),
"country" : "India da address",
"custom" : true
}
],
"mandatory" : true,
"allowForGroups" : false
},
-----------
}
When i query the document using following query:
companyCollection.find($doc("_id" $eq companyId, "location._id" $eq locationId)).projection($doc("location" -> 1, "_id" -> 1)).cursor[LocationField].headOption;
It will return only company id
. But when i change the projection value to projection($doc("location" -> 1, "_id" -> 0))
it return empty document. I am using Query DSL for write the queries.
UPDATE
When i create query like:
companyCollection.find($doc("_id" $eq companyId, "department._id" $eq departmentId), $doc("department" -> 1, "_id" -> 0)).cursor[Company].headOption
with this my return value is map with Company
and with its property LocationField
using projection and rest of the fields are ignore by mongodb. But my basic requirement is return only location
inner document value and map with LocationField
. When i run query in mongo db console like :
db.companies.find({"_id": ObjectId('5592c0e6ea16e552ac90e169'), "location._id": ObjectId('5592c17fc3ad8cbffa0e9778')}, {"location": 1, "_id": 0})
The result behavior is same as my reactive mongo query. Is it possible with mongo db for return only inner document, instead of full document structure?