Is there a way to use $Set in inside a $map in a projection - mongodb

I m trying to update a value inside a map in projection. How can i update a field inside the map? I m trying to do calculation on chargeAmount which will be updated in the loop.
I m using MongoDB shell version v4.0.6 in ubuntu 18.04
{
$project : {
"initialAmount": "$chargeAmount",
"taxedData":{
$map:
{
input: "$rateTaxLevel",
as: "taxIds",
in: {
$map:
{
input: "$taxValidity",
as: "levels",
in: {
//$add: [ "$$taxIds.taxid", "$$levels.taxid" ]
taxingAmount:
{
$cond: [ { $eq: [ "$$taxIds.taxid", "$$levels.taxid" ] },
{ $divide: [ "initialAmount",{ $add: [ 1, "$$levels.tax_validityval" ]} ]
//"$$levels.tax_validityval"
} ,"$$REMOVE"
]
},
"chargeAmount" : "$taxingAmount"
}
}
}
}
}
}
}
data set which used in the project stage
{
"_id" : ObjectId("5caae957beca0f79bddc46d9"),
"uuid" : "urn:uuid:dbc692c7-898c-42c0-ae4d-73f03ed39434:0001PAYMENT93",
"responseTime" : NumberLong(1552589459734),
"direction" : "nb",
"api" : "payment",
"apiID" : "payment_v1",
"applicationName" : "buddhitest",
"applicationId" : NumberInt(93),
"serviceProvider" : "buddhinipun#carbon.super",
"serviceProviderId" : "buddhinipun#carbon.super",
"operatorName" : "OPERATOR1",
"operatorId" : NumberInt(1),
"operation" : "Charge",
"operatorRef" : "ABC-11111113589301",
"chargeAmount" : NumberInt(100),
"category" : "111",
"subcategory" : "222",
"merchant" : "111",
"responseCount" : "1",
"rateCard" : "common_percentage",
"price" : -9.1,
"year" : NumberInt(2019),
"month" : NumberInt(3),
"day" : NumberInt(14),
"hour" : NumberInt(19),
"status" : NumberInt(0),
"statusInfo" : "ok",
"userType" : " Postpaid",
"subRateNB" : [
{
"_id" : ObjectId("5cac45a037c54a0f4ce2b717"),
"sub_rate_nbid" : NumberInt(17),
"api_operationid" : NumberInt(1),
"api_version" : "v1",
"applicationid" : NumberInt(93),
"rate_defid" : NumberInt(30),
"sub_rate_nbactdate" : null,
"sub_rate_nbdisdate" : null,
"createdby" : null,
"createddate" : ISODate("2019-01-16T18:31:18.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2019-01-16T18:31:18.000+0000")
}
],
"rateTaxLevel" : [
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a7"),
"rate_taxesid" : NumberInt(177),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(40),
"level" : NumberInt(1)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a8"),
"rate_taxesid" : NumberInt(178),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(41),
"level" : NumberInt(2)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a9"),
"rate_taxesid" : NumberInt(179),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(1),
"level" : NumberInt(3)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7aa"),
"rate_taxesid" : NumberInt(180),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(66),
"level" : NumberInt(4)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7ab"),
"rate_taxesid" : NumberInt(181),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(68),
"level" : NumberInt(5)
}
],
"taxValidity" : [
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7be"),
"idtax_validityid" : NumberInt(1),
"tax_validityactdate" : ISODate("2018-10-09T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2020-10-09T18:30:00.000+0000"),
"tax_validityval" : 0.02,
"taxid" : NumberInt(1),
"createdby" : null,
"createddate" : ISODate("2018-10-26T13:05:58.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-26T13:05:58.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7d5"),
"idtax_validityid" : NumberInt(27),
"tax_validityactdate" : ISODate("2018-10-29T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2035-11-10T18:30:00.000+0000"),
"tax_validityval" : 0.5,
"taxid" : NumberInt(40),
"createdby" : null,
"createddate" : ISODate("2018-10-30T17:31:40.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-30T17:31:40.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7d6"),
"idtax_validityid" : NumberInt(28),
"tax_validityactdate" : ISODate("2018-10-31T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-11-07T18:30:00.000+0000"),
"tax_validityval" : 2.0,
"taxid" : NumberInt(41),
"createdby" : null,
"createddate" : ISODate("2018-10-30T17:42:20.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-30T17:42:20.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7ec"),
"idtax_validityid" : NumberInt(50),
"tax_validityactdate" : ISODate("2018-11-11T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-11-30T18:30:00.000+0000"),
"tax_validityval" : 0.23,
"taxid" : NumberInt(66),
"createdby" : null,
"createddate" : ISODate("2018-11-12T20:22:47.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-11-12T20:22:47.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7ee"),
"idtax_validityid" : NumberInt(52),
"tax_validityactdate" : ISODate("2018-11-30T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-12-07T18:30:00.000+0000"),
"tax_validityval" : 0.01,
"taxid" : NumberInt(68),
"createdby" : null,
"createddate" : ISODate("2018-11-26T15:02:51.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-11-26T15:02:51.000+0000")
}
]
}
// ----------------------------------------------
{
"_id" : ObjectId("5caae957beca0f79bddc46da"),
"uuid" : "urn:uuid:a566d97b-8032-47d2-aef3-ad5807af3742:0001PAYMENT93",
"responseTime" : NumberLong(1552895806695),
"direction" : "nb",
"api" : "payment",
"apiID" : "payment_v1",
"applicationName" : "buddhitest",
"applicationId" : NumberInt(93),
"serviceProvider" : "buddhinipun#carbon.super",
"serviceProviderId" : "buddhinipun#carbon.super",
"operatorName" : "OPERATOR1",
"operatorId" : NumberInt(1),
"operation" : "Charge",
"operatorRef" : "ABC-123",
"chargeAmount" : NumberInt(10),
"category" : "",
"subcategory" : "",
"merchant" : "",
"responseCount" : "1",
"rateCard" : "common_percentage",
"price" : -0.91,
"year" : NumberInt(2019),
"month" : NumberInt(3),
"day" : NumberInt(18),
"hour" : NumberInt(8),
"status" : NumberInt(0),
"statusInfo" : "ok",
"userType" : " Postpaid",
"subRateNB" : [
{
"_id" : ObjectId("5cac45a037c54a0f4ce2b717"),
"sub_rate_nbid" : NumberInt(17),
"api_operationid" : NumberInt(1),
"api_version" : "v1",
"applicationid" : NumberInt(93),
"rate_defid" : NumberInt(30),
"sub_rate_nbactdate" : null,
"sub_rate_nbdisdate" : null,
"createdby" : null,
"createddate" : ISODate("2019-01-16T18:31:18.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2019-01-16T18:31:18.000+0000")
}
],
"rateTaxLevel" : [
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a7"),
"rate_taxesid" : NumberInt(177),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(40),
"level" : NumberInt(1)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a8"),
"rate_taxesid" : NumberInt(178),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(41),
"level" : NumberInt(2)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7a9"),
"rate_taxesid" : NumberInt(179),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(1),
"level" : NumberInt(3)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7aa"),
"rate_taxesid" : NumberInt(180),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(66),
"level" : NumberInt(4)
},
{
"_id" : ObjectId("5cac45c437c54a0f4ce2b7ab"),
"rate_taxesid" : NumberInt(181),
"rate_defid" : NumberInt(30),
"taxid" : NumberInt(68),
"level" : NumberInt(5)
}
],
"taxValidity" : [
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7be"),
"idtax_validityid" : NumberInt(1),
"tax_validityactdate" : ISODate("2018-10-09T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2020-10-09T18:30:00.000+0000"),
"tax_validityval" : 0.02,
"taxid" : NumberInt(1),
"createdby" : null,
"createddate" : ISODate("2018-10-26T13:05:58.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-26T13:05:58.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7d5"),
"idtax_validityid" : NumberInt(27),
"tax_validityactdate" : ISODate("2018-10-29T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2035-11-10T18:30:00.000+0000"),
"tax_validityval" : 0.5,
"taxid" : NumberInt(40),
"createdby" : null,
"createddate" : ISODate("2018-10-30T17:31:40.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-30T17:31:40.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7d6"),
"idtax_validityid" : NumberInt(28),
"tax_validityactdate" : ISODate("2018-10-31T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-11-07T18:30:00.000+0000"),
"tax_validityval" : 2.0,
"taxid" : NumberInt(41),
"createdby" : null,
"createddate" : ISODate("2018-10-30T17:42:20.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-10-30T17:42:20.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7ec"),
"idtax_validityid" : NumberInt(50),
"tax_validityactdate" : ISODate("2018-11-11T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-11-30T18:30:00.000+0000"),
"tax_validityval" : 0.23,
"taxid" : NumberInt(66),
"createdby" : null,
"createddate" : ISODate("2018-11-12T20:22:47.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-11-12T20:22:47.000+0000")
},
{
"_id" : ObjectId("5cac469137c54a0f4ce2b7ee"),
"idtax_validityid" : NumberInt(52),
"tax_validityactdate" : ISODate("2018-11-30T18:30:00.000+0000"),
"tax_validitydisdate" : ISODate("2018-12-07T18:30:00.000+0000"),
"tax_validityval" : 0.01,
"taxid" : NumberInt(68),
"createdby" : null,
"createddate" : ISODate("2018-11-26T15:02:51.000+0000"),
"updatedby" : null,
"updateddate" : ISODate("2018-11-26T15:02:51.000+0000")
}
]
}
// ----------------------------------------------
I got this result using java script function
"------------------------------------"
"l1Tax% : 1.02"
"l1Tax : 98.0392156862745"
"l2Tax% : 1.5"
"l2Tax : 65.359477124183"
"l3Tax% : 3"
"l3Tax : 21.78649237472767"
"l4Tax% : 1.23"
"l4Tax : 17.712595426607862"
"l5Tax% : 1.01"
"l5Tax : 17.537223194661248"
"------------------------------------"
"l1Tax% : 1.02"
"l1Tax : 9.803921568627452"
"l2Tax% : 1.5"
"l2Tax : 6.535947712418301"
"l3Tax% : 3"
"l3Tax : 2.1786492374727673"
"l4Tax% : 1.23"
"l4Tax : 1.7712595426607864"
"l5Tax% : 1.01"
"l5Tax : 1.7537223194661251"
using the below java script function, I was able to get the desired output but there is significant performance drop in the java script approach.
forEach(function (doc) {
var taxableamount = doc.chargeAmount;
var taxedAmmount =0;
printjson("------------------------------------");
for (index = 0; index < doc.rateTaxLevel.length; index++) {
for (index = 0; index < doc.taxValidity.length; index++) {
taxedAmmount = taxableamount / (1+doc.taxValidity[index].tax_validityval);
taxableamount = taxedAmmount;
printjson("l"+doc.rateTaxLevel[index].level+"Tax% : "+(1+doc.taxValidity[index].tax_validityval));
printjson("l"+doc.rateTaxLevel[index].level+"Tax : "+taxableamount);
}
}
}

Related

Mongodb agregation. how to enter a list of all hosts who received at least two negative ratings (5 or less) for each review

this is example of document. Now i want to get all host who received at least two negative ratings (5 or less) for each review.
{
"_id" : "5bf31f8c856a12c73c888cee",
"index" : NumberInt(0),
"guid" : "f99844b5-7ecd-4c90-860f-b79a742fcac1",
"isActive" : true,
"registered" : "2012-06-14T02:14:30 -02:00",
"host" : {
"name" : "Grimes",
"surname" : "Terrell",
"gender" : "male",
"age" : NumberInt(55),
"picture" : "https://api.adorable.io/avatars/285/GrimesTerrell.png",
"languages" : [
"spanish",
"slovenian",
"english"
],
"contact" : {
"company" : "QUANTALIA",
"email" : "grimesterrell#quantalia.com",
"phone" : "+1 (987) 474-3543"
},
"reviews" : [
{
"reviewer" : "Mae Ryan",
"date" : "2015-06-01T02:41:46 -02:00",
"helpful" : NumberInt(8),
"kind" : NumberInt(1),
"responsive" : NumberInt(5)
},
{
"reviewer" : "Nixon Johnson",
"date" : "2016-02-08T10:35:12 -01:00",
"helpful" : NumberInt(1),
"kind" : NumberInt(1),
"responsive" : NumberInt(9)
},
{
"reviewer" : "Dorothy Copeland",
"date" : "2016-07-17T12:44:31 -02:00",
"helpful" : NumberInt(3),
"kind" : NumberInt(3),
"responsive" : NumberInt(4)
},
{
"reviewer" : "Kathleen Roth",
"date" : "2014-12-26T04:38:36 -01:00",
"helpful" : NumberInt(10),
"kind" : NumberInt(3),
"responsive" : NumberInt(5)
},
{
"reviewer" : "Hallie Hart",
"date" : "2016-02-14T10:21:50 -01:00",
"helpful" : NumberInt(9),
"kind" : NumberInt(4),
"responsive" : NumberInt(9)
}
]
},
"lodging" : {
"price" : "$86",
"address" : {
"street" : "645 Louisa Street",
"city" : "Fairhaven",
"state" : "Nebraska",
"coordinates" : [
5.439653,
30.761532
]
},
"amenities" : {
"parking" : true,
"petsAllowed" : true,
"airConditioning" : true,
"elevator" : true
},
"reviews" : [
{
"reviewer" : "Susanne Walton",
"date" : "2018-03-20T04:50:18 -01:00",
"cleanliness" : NumberInt(8),
"location" : NumberInt(1),
"food" : NumberInt(10)
},
{
"reviewer" : "Henrietta Manning",
"date" : "2017-12-14T07:05:46 -01:00",
"cleanliness" : NumberInt(10),
"location" : NumberInt(5),
"food" : NumberInt(1)
},
{
"reviewer" : "Newman West",
"date" : "2018-05-07T05:23:55 -02:00",
"cleanliness" : NumberInt(9),
"location" : NumberInt(10),
"food" : NumberInt(6)
},
{
"reviewer" : "Brennan Rowland",
"date" : "2016-09-20T04:49:15 -02:00",
"cleanliness" : NumberInt(10),
"location" : NumberInt(1),
"food" : NumberInt(8)
},
{
"reviewer" : "Beulah Lambert",
"date" : "2016-04-20T11:51:43 -02:00",
"cleanliness" : NumberInt(4),
"location" : NumberInt(8),
"food" : NumberInt(9)
},
{
"reviewer" : "Joseph Mcdowell",
"date" : "2015-02-10T12:14:20 -01:00",
"cleanliness" : NumberInt(7),
"location" : NumberInt(9),
"food" : NumberInt(3)
}
]
}
}
i dont now how to loop trough all host reviews and then check if any of two (helpfull or kind or responsive) are less than 5 and if all have such reviews how to project those to output. i am new to mongodb:)
db.lodging.aggregate([
{
$project: {
'host': 1,
numberOfReviews: { $size: '$host.reviews' },
}
}
])
i tried to and new filed to each review with true or false where false mean that there are no two negative rating and true mean that there are two negative ratings (les than or equal 5)
but if statement dont work corectly
db.lodging.aggregate([
{
$project: {
'host': 1,
steviloKritik: { $size: '$host.reviews' },
}
},
{
$addFields: {
"host.reviews.condition": {
$cond: [{ $lte: ["$host.reviews.helpful", 5] }, true, false]
}
}
},
])

Update nested documents inside array based on condition

i have the next document and i have to update promotion object according to promotionId
executing i can update, but this query erases the other products that have no the promotion in the condition:
if i use update many i get Error: the update operation document must contain atomic operators.
Please help me to get the error to update but keeping the products that does not have the promo i am updating.
/* 1 */
db.fulFillmentCenter.update({},[
{
$addFields: {
exclusiveProducts: {
$filter: {
input: "$exclusiveProducts",
as: "product",
cond: {
$eq: [
"$$product.promotion.promotionId",
'promo1'
]
}
}
}
}
},
{$set: { "exclusiveProducts.promotion.description": "multi 2"}}
/* 2 */
{
"_id" : 1,
"_class" : "com.walmart.labsmx.exclusiveproducts.model.FulFillmentCenter",
"minDateDelivery" : 9,
"maxDateDelivery" : 2,
"deliveryCost" : 10.0,
"origin" : "string",
"active" : true,
"exclusiveProducts" : [
{
"_id" : NumberLong(1585867035599),
"upc" : "p1",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-04-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035613),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035642),
"upc" : "p2",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-04-10T02:47:03.472Z"),
"active" : false,
"promotion" : {
"_id" : NumberLong(1585867035654),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035607),
"upc" : "p3",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-03-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035668),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035644),
"upc" : "p4",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-05-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035632),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035666),
"upc" : "p5",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035591),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035669),
"upc" : "p20",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035661),
"promotionId" : "promo2",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035643),
"upc" : "p21",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035612),
"promotionId" : "promo3",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
}
],
"exclusiveStores" : [
{
"storeId" : 123,
"origin" : "string"
}
]
}
This update query updates all the nested documents promotion within the array exclusiveProducts. The value of "promotion.description" is modified with the new value "multi 2", where the "promotion.promotionId" = "promo1".
var new_desc = "multi 2";
db.collection.updateMany(
{ "exclusiveProducts.promotion.promotionId": "promo1" },
{ $set: { "exclusiveProducts.$[pr].promotion.description": new_desc } },
{ arrayFilters: [ { "pr.promotion.promotionId": "promo1" } ] }
)

String to ISO Date

I've looked this up a few times and no answer has worked so far. I want to turn a string date into an ISODate - I don't want it converted to or from UTC, I just want to make the date value which is stored as string to be stored as a date.
I don't want UTC because I want to query against and calculate based upon a time of day (example: 12pm) anywhere in the world and I'm summing by hour, day, week and month and comparing data across many countries based upon local time.
Currently I have a date as a string which I want to add to a new document with a new name:
"transaction_date": "$object_raw_origin_data.register_sales.sale_date"
The date value as string below is shown as:
"sale_date" : "2018-03-13 20:05:46"
I want it to be: "transaction_date" : ISODate("2018-03-13 20:05:46")
The date and time must read 2018-03-13 20:05:46 not converted to UTC.
Thanks, Matt
Origin Data JSON
{
"object_category" : "application",
"object_type" : "register-sales-24-months",
"object_origin" : "vend",
"tenant_uuid" : "00000000-0000-0009-9999-999999999999",
"party_uuid" : "8d519765-05d2-469f-ad35-d7a22fa9df2f",
"subscription_uuid" : "0",
"connection_uuid" : "6ed9bd79-d9c5-4296-a821-7e15b1c69e6c",
"status" : "",
"object_created" : ISODate("2018-03-15T21:40:57.158+0000"),
"object_raw_origin_data" : {
"pagination" : {
"results" : NumberInt(75964),
"page" : NumberInt(1),
"page_size" : NumberInt(200),
"pages" : NumberInt(380)
},
"register_sales" : {
"id" : "776a66f2-993c-b372-11e8-26f9d3c1bdde",
"source" : "USER",
"source_id" : "",
"register_id" : "02dcd191-ae55-11e6-edd8-ec8dce1d9e1c",
"market_id" : "3",
"customer_id" : "02d59481-b67d-11e5-f667-b08185e8f6d5",
"customer_name" : "",
"customer" : {
"id" : "02d59481-b67d-11e5-f667-b08185e8f6d5",
"name" : "",
"customer_code" : "WALKIN",
"customer_group_id" : "02d59481-b67d-11e5-f667-b08185e893f8",
"customer_group_name" : "All Customers",
"updated_at" : "2016-01-01 12:16:44",
"deleted_at" : "",
"balance" : "0",
"year_to_date" : "0",
"date_of_birth" : "",
"sex" : "",
"custom_field_1" : "",
"custom_field_2" : "",
"custom_field_3" : "",
"custom_field_4" : "",
"note" : "",
"contact" : {
}
},
"user_id" : "02d59481-b655-11e5-f667-dca974edc4ea",
"user_name" : "Alvaro Velosa",
"sale_date" : "2018-03-13 20:05:46",
"created_at" : "2018-03-13 20:06:00",
"updated_at" : "2018-03-13 20:06:00",
"total_price" : 4.5,
"total_cost" : 3.34,
"total_tax" : NumberInt(0),
"tax_name" : "No Tax",
"note" : "",
"status" : "CLOSED",
"short_code" : "wqgsgi",
"invoice_number" : "Masonic2108Temple",
"accounts_transaction_id" : "",
"return_for" : "",
"register_sale_products" : [
{
"id" : "776a66f2-993c-b372-11e8-26f9e92cb9bc",
"product_id" : "02dcd191-ae55-11e7-f130-9d4f4bcd91b1",
"register_id" : "02dcd191-ae55-11e6-edd8-ec8dce1d9e1c",
"sequence" : "0",
"handle" : "LAGERDRAUGHT300",
"sku" : "10287",
"name" : "LAGER DRAUGHT £3.00",
"quantity" : NumberInt(1),
"price" : 3.5,
"cost" : 2.74,
"price_set" : NumberInt(0),
"discount" : NumberInt(0),
"loyalty_value" : NumberInt(0),
"tax" : NumberInt(0),
"tax_id" : "02d59481-b67d-11e5-f667-b08185ec2871",
"tax_name" : "No Tax",
"tax_rate" : NumberInt(0),
"tax_total" : NumberInt(0),
"price_total" : 3.5,
"display_retail_price_tax_inclusive" : "0",
"status" : "CONFIRMED",
"attributes" : [
{
"name" : "line_note",
"value" : ""
}
]
},
{
"id" : "776a66f2-993c-b372-11e8-26f9e98104e0",
"product_id" : "02dcd191-ae55-11e7-f130-9d50e948a0b5",
"register_id" : "02dcd191-ae55-11e6-edd8-ec8dce1d9e1c",
"sequence" : "0",
"handle" : "SOFTDRINK",
"sku" : "10292",
"name" : "SOFT DRINK",
"quantity" : NumberInt(1),
"price" : NumberInt(1),
"cost" : 0.6,
"price_set" : NumberInt(0),
"discount" : NumberInt(0),
"loyalty_value" : NumberInt(0),
"tax" : NumberInt(0),
"tax_id" : "02d59481-b67d-11e5-f667-b08185ec2871",
"tax_name" : "No Tax",
"tax_rate" : NumberInt(0),
"tax_total" : NumberInt(0),
"price_total" : NumberInt(1),
"display_retail_price_tax_inclusive" : "0",
"status" : "CONFIRMED",
"attributes" : [
{
"name" : "line_note",
"value" : ""
}
]
}
],
"totals" : {
"total_tax" : NumberInt(0),
"total_price" : 4.5,
"total_payment" : 4.5,
"total_to_pay" : NumberInt(0)
},
"register_sale_payments" : [
{
"id" : "776a66f2-993c-b372-11e8-26f9eab2cb46",
"payment_type_id" : "1",
"register_id" : "02dcd191-ae55-11e6-edd8-ec8dce1d9e1c",
"retailer_payment_type_id" : "02d59481-b655-11e5-f667-b0a23bc0e7bc",
"name" : "Cash",
"label" : "Account Customer",
"payment_date" : "2018-03-13 20:05:46",
"amount" : NumberInt(10)
},
{
"id" : "776a66f2-993c-b372-11e8-26f9eab6b21a",
"payment_type_id" : "1",
"register_id" : "02dcd191-ae55-11e6-edd8-ec8dce1d9e1c",
"retailer_payment_type_id" : "02d59481-b655-11e5-f667-b0a23bc0e7bc",
"name" : "Cash",
"label" : "Account Customer",
"payment_date" : "2018-03-13 20:05:46",
"amount" : -5.5
}
]
}
}
}
Thanks for the help from #Saleem and #Krishna however, I have tried to create an ISODate using a $concat of $substr from a string and it isn't working.
db.Vend_raw_transactions.aggregate(
[{
"$project": {
"object_origin": "$object_origin",
"company": "$party_uuid",
"connection": "$connection_uuid",
"object_creation_date": "$object_created",
// "transaction_date": "$object_raw_origin_data.register_sales.sale_date",
"transaction_date": {
"$dateFromString": {
"dateString": {
"$concat": [
"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 0, 10 ],
"T",
"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 11, 9]
]
}
}
},
"transaction_gross_value": {
"$add": [
"$object_raw_origin_data.register_sales.total_price",
"$object_raw_origin_data.register_sales.total_tax"
]
},
"transaction_net_value": "$object_raw_origin_data.register_sales.total_price",
"transaction_tax_value": "$object_raw_origin_data.register_sales.total_tax",
"transaction_cost_value": "$object_raw_origin_data.register_sales.total_cost",
"object_class": "goods-service-transaction",
"object_origin_category": "point-of-sale",
"object_type": "receipt",
"object_origin_type": "offline",
"transaction_reference": "$object_raw_origin_data.register_sales.invoice_number",
"transaction_status": "$object_raw_origin_data.register_sales.status",
"transaction_currency": "GBP",
"party_name": "$object_raw_origin_data.register_sales.customer.customer_name",
"party_identifier": "$object_raw_origin_data.register_sales.customer.customer_code",
"staff_identifier": "$object_raw_origin_data.register_sales.user_id",
"staff_name": "$object_raw_origin_data.register_sales.user_name",
"line_items" : {
"$map": {
"input": "$object_raw_origin_data.register_sales.register_sale_products",
"as" : "product",
"in": {"item_name": "$$product.name",
"item_system_id": "$$product.id",
"item_identifier": "$$product.sku",
"item_category" : "sales-revenue",
"item_quantity" : "$$product.quantity",
"item_net_unit_sale_value" : "$$product.price",
"item_net_unit_discount_value" : "$$product.discount",
"item_net_unit_member_value" : "$$product.loyalty_value",
"item_net_unit_cost_value" : "$$product.cost",
"item_unit_tax_value" : "$$product.tax",
"item_price_list_reference" : "$$product.price_set",
"item_total_sale_value" : "$$product.price_total",
"item_total_tax_value" : "$$product.tax_total"
}
}
}
}
}
// ,{"$out": "9SP_Source" }
])
I cannot work out why this isn't working, it seems like it should - I'm creating a new string based upon an existing string value and adding a T in the middle but it doesn't recognise $DateFromString. Thanks
Error Message
{
"message" : "Unrecognized expression '$dateFromString'",
"stack" : "MongoError: Unrecognized expression '$dateFromString'" +
"at queryCallback (C:\Users\mattl\AppData\Local\Programs\nosqlbooster4mongo\resources\app.asar\node_modules\mongodb-core\lib\cursor.js:223:25)" +
"at C:\Users\mattl\AppData\Local\Programs\nosqlbooster4mongo\resources\app.asar\node_modules\mongodb-core\lib\connection\pool.js:541:18" +
"at _combinedTickCallback (internal/process/next_tick.js:131:7)" +
"at process._tickCallback (internal/process/next_tick.js:180:9)",
"name" : "MongoError",
"ok" : 0,
"errmsg" : "Unrecognized expression '$dateFromString'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"
}
I've managed to make another string using the below script but $dateFromString unrecognised
db.Vend_raw_transactions.aggregate(
[{
"$project": {
"origin_date": "$object_raw_origin_data.register_sales.sale_date",
"transaction_date": {
"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 0, 10 ]
},
"transaction_time": {
"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 11, 9 ]
},
"new_string_date": {
"$concat" :[
{"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 0, 10 ]},
"T",
{"$substr": [ "$object_raw_origin_data.register_sales.sale_date", 11, 9 ]}]
}
}
}
])
Thanks

Need Help Join Collection

Collection Inventory sample data:
{
"_id" : "89011704252315531324",
"sku" : "A2015-01-000",
"type" : "package",
"status" : "active",
"lng" : "-72.789153",
"lat" : "44.173515",
"acq" : "28",
"gtime" : ISODate("2017-01-11T22:27:48.000Z"),
"qlng" : "-72.796501",
"qlat" : "44.214783",
"qtime" : ISODate("2016-11-27T18:21:10.000Z"),
"timestamp" : ISODate("2017-01-12T14:43:29.000Z"),
"modified" : Date(-62135596800000),
"battery" : "60",
"wearables" : [
{
"_id" : "0009003C100228234E45",
"type" : "wearable",
"status" : "active",
"battery" : "50",
"timestamp" : ISODate("2017-01-12T11:43:33.000Z")
},
{
"_id" : "004A003F200B36634E45",
"type" : "cradle",
"status" : "active",
"battery" : "64",
"timestamp" : ISODate("2017-01-11T22:27:26.000Z")
},
{
"_id" : "11223344556600000B55",
"type" : "falldetect",
"status" : "active",
"battery" : "64",
"timestamp" : ISODate("2017-01-12T08:43:29.000Z")
}
],
"company" : "ConnectAmericaProduction",
"companies" : [],
"remoteIp" : "172.31.45.196:53864",
"subscriber" : "5783e20aa2c89f346e000006",
"ring" : "90",
"speaker" : "90",
"mic" : "55",
"version" : "4352",
"cradle" : "OFF",
"ctime" : ISODate("2017-01-11T23:13:59.000Z"),
"csqtime" : Date(-62135596800000)
}
collection calllog sample data
{
"_id" : "89011704252315531324",
"cdr" : [
{
"direction" : "Outgoing",
"duration" : 46,
"timestamp" : ISODate("2016-11-23T03:25:06.000Z"),
"number" : "",
"name" : "Call Center",
"lng" : "-71.208061",
"lat" : "42.330265",
"acq" : "",
"timezone" : {
"dstOffset" : 0.0,
"rawOffset" : 0.0,
"status" : "",
"timeZoneId" : "",
"timeZoneName" : ""
}
},
{
"direction" : "Incoming",
"duration" : 51,
"timestamp" : ISODate("2016-11-23T03:26:02.000Z"),
"number" : "",
"name" : "Call Center",
"lng" : "-71.205727",
"lat" : "42.333347",
"acq" : "",
"timezone" : {
"dstOffset" : 0.0,
"rawOffset" : 0.0,
"status" : "",
"timeZoneId" : "",
"timeZoneName" : ""
}
},
{
"direction" : "Outgoing",
"duration" : 49,
"timestamp" : ISODate("2016-11-27T18:21:04.000Z"),
"number" : "",
"name" : "Call Center",
"lng" : "-72.796501",
"lat" : "44.214783",
"acq" : "",
"timezone" : {
"dstOffset" : 0.0,
"rawOffset" : -18000.0,
"status" : "OK",
"timeZoneId" : "America/New_York",
"timeZoneName" : "Eastern Standard Time"
}
}
]
}
after run this aggrgrate function
db.calllog.aggregate([{$unwind: "$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as: "wearables" }}, { "$project": { "cdr.direction": 1, "cdr.duration": 1,"cdr.date": 1,"wearables.type": 1, "wearables.status": 1, "wearables.battery": 1} }])
Result:
{ "_id" : "89011704252315531324", "cdr" : { "direction" : "Outgoing", "duration" : 46 }, "wearables" : [ { "type" : "package", "status" : "active", "battery" : "60" } ] }
{ "_id" : "89011704252315531324", "cdr" : { "direction" : "Incoming", "duration" : 51 }, "wearables" : [ { "type" : "package", "status" : "active", "battery" : "60" } ] }
{ "_id" : "89011704252315531324", "cdr" : { "direction" : "Outgoing", "duration" : 49 }, "wearables" : [ { "type" : "package", "status" : "active", "battery" : "60" } ] }
needed help can not get query to shows wearables type such as wearable, cradle, falldetect
thank
Did you try to do wearables.wearables.type? When you call wearables.type, you are actually getting the type of the Inventory. If you need the type of the wearable that is inside the inventory. You need to put inventory.wearables.type. The initial problem is that you're calling the inventory "wearables" and making a confusion out of it.
I would do the following:
db.calllog.aggregate([{$unwind: "$cdr"},
{$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as: "inventory" }},
{$unwind: "$inventory.wearables"},
{ "$project": {
"cdr.direction": 1,
"cdr.duration": 1,
"cdr.date": 1,
"inventory.type": 1,
"inventory.status": 1,
"inventory.battery": 1,
"inventory.wearables.type":1
}}])

$nearSphere returns too many data

I noticed that $near and $nearSphere returns completely different data and I got suspicious. After all, when latitude is near equator it sphere distance shouldn't differ a lot from euclidean distance.
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^soto/, /^nasi/] } }).limit(200);
It returns 48 data.
I'll attached it anyway
/* 0 */
{
"_id" : "nasi-uduk-soto-ayam__-6.18_106.77",
"BuildingID" : null,
"Title" : "Nasi Uduk Soto Ayam",
"InBuildingAddress" : null,
"Building" : null,
"Street" : "Jl. Panjang",
"Districts" : [],
"City" : "Jakarta",
"Country" : "Indonesia",
"LongitudeLatitudeFromGoogle" : null,
"DistanceFromGoogleAddress" : 0.0,
"Checkin" : 0,
"Note" : null,
"PeopleCount" : 0,
"Prominent" : 45.5,
"CountViews" : 0,
"StreetAdditional" : null,
"LongitudeLatitude" : {
"Longitude" : 106.765673160553,
"Latitude" : -6.17522230915668
},
"Rating" : {
"Stars" : 0.0,
"Weight" : 0.0
},
"CurrentlyWorkedURL" : null,
"Reviews" : [],
"ZIP" : null,
"Tags" : ["Restaurant"],
"Phones" : [],
"Website" : null,
"Email" : null,
"Price" : null,
"openingHour" : null,
"Promotions" : [],
"SomethingWrong" : false,
"BizMenus" : [],
"Brochures" : [],
"Aliases" : [],
"indexContents" : ["restaura", "estauran", "staurant", "taurant", "aurant", "urant", "rant", "ant", "nt", "t", "nasi", "asi", "si", "i", "uduk", "duk", "uk", "k", "soto", "oto", "to", "o", "ayam", "yam", "am", "m"]
}
/* 1 */
{
"_id" : "nasi-soto-padang_pasar-slipi-jaya_-6.19_106.80",
"BuildingID" : null,
"Title" : "Nasi Soto Padang",
"InBuildingAddress" : "Lt.1 Los Alas",
"Building" : null,
"Street" : "Jl.Kemanggisan Utama Raya",
"Districts" : [],
"City" : "Jakarta",
"Country" : "Indonesia",
"LongitudeLatitudeFromGoogle" : null,
"DistanceFromGoogleAddress" : 0.0,
"Checkin" : 0,
"Note" : null,
"PeopleCount" : 0,
"Prominent" : 45.5,
"CountViews" : 0,
"StreetAdditional" : null,
"LongitudeLatitude" : {
"Longitude" : 106.79647564888,
"Latitude" : -6.18998465381734
},
"Rating" : {
"Stars" : 0.0,
"Weight" : 0.0
},
"CurrentlyWorkedURL" : null,
"Reviews" : [],
"ZIP" : null,
"Tags" : ["Restaurant"],
"Phones" : [],
"Website" : null,
"Email" : null,
"Price" : null,
"openingHour" : null,
"Promotions" : [],
"SomethingWrong" : false,
"BizMenus" : [],
"Brochures" : [],
"Aliases" : [],
"indexContents" : ["restaura", "estauran", "staurant", "taurant", "aurant", "urant", "rant", "ant", "nt", "t", "nasi", "asi", "si", "i", "soto", "oto", "to", "o", "padang", "adang", "dang", "ang", "ng", "g"]
}
...
/* 47 */
{
"_id" : "nasi-gandul__-7.43_109.24",
"BuildingID" : null,
"Title" : "Nasi Gandul",
"InBuildingAddress" : null,
"Building" : null,
"Street" : "Jl. Brobahan Pr - 40 rt 004 Rw 004",
"Districts" : [],
"City" : "Purwokerto",
"Country" : "Indonesia",
"LongitudeLatitudeFromGoogle" : null,
"DistanceFromGoogleAddress" : 0.0,
"Checkin" : 0,
"Note" : null,
"PeopleCount" : 0,
"Prominent" : 30.5,
"CountViews" : 0,
"StreetAdditional" : null,
"LongitudeLatitude" : {
"Longitude" : 109.239182174206,
"Latitude" : -7.42585664273589
},
"Rating" : {
"Stars" : 3.0,
"Weight" : 1.0
},
"CurrentlyWorkedURL" : null,
"Reviews" : [],
"ZIP" : "53116",
"Tags" : ["Angkringan", "Restaurant Indonesian", "Soto & Sop"],
"Phones" : ["+62(281)7918181"],
"Website" : null,
"Email" : null,
"Price" : null,
"openingHour" : null,
"Promotions" : [],
"SomethingWrong" : false,
"BizMenus" : [],
"Brochures" : [],
"Aliases" : [],
"indexContents" : ["angkring", "ngkringa", "gkringan", "kringan", "ringan", "ingan", "ngan", "gan", "an", "n", "restaura", "estauran", "staurant", "taurant", "aurant", "urant", "rant", "ant", "nt", "t", "indonesi", "ndonesia", "donesian", "onesian", "nesian", "esian", "sian", "ian", "soto", "oto", "to", "o", "&", "sop", "op", "p", "nasi", "asi", "si", "i", "gandul", "andul", "ndul", "dul", "ul", "l"]
}
I put the data into excel and compute the distance using this formula
=SQRT(POWER(E2-$G$1,2)+POWER((F2-$H$1)*COS($H$1*PI()/180),2))
That one should greatly approximate spherical distance. Also notice that latitude is -6 which is not far from equator.
Here is the result
0.013516826
0.023857967
0.037658667
0.038737146
0.042414787
0.046725248
0.051006427
0.053567221
0.057448344
0.061592999
0.062329244
0.065276161
0.066035611
0.076251787
0.109671831
0.112097201
0.13417281
0.136471939
0.172293693
1.058802838
1.078123028
1.079160684
1.080954023
1.081148114
1.081099449
1.092061283
1.094281476
1.094431917
1.096845722
1.097063729
1.096953691
1.097201996
1.105389179
1.105442127
1.10839237
1.108717834
1.108840349
1.111636423
1.113187903
1.118767984
1.118767984
1.133952371
1.135077548
1.154967917
1.161142923
1.185994885
1.199509086
2.756884824
Here is the screenshot of my excel sheet
Here is the actual excel
106.772835 -6.186753
"_id" "nasi-uduk-soto-ayam__-6.18_106.77", 106.7656732 -6.175222309 0.013516826
"_id" "nasi-soto-padang_pasar-slipi-jaya_-6.19_106.80", 106.7964756 -6.189984654 0.023857967
"_id" "nasi-uduk-soto-ayam__-6.22_106.77", 106.7718959 -6.224620499 0.037658667
"_id" "nasi-campur-%26-soto-babat-kenanga_komp.-ruko-permata-senayan%2C_-6.22_106.79", 106.79199 -6.22062 0.038737146
"_id" "soto-mie-nasi_indomaret-(univ.-mercu-buana)_-6.21_106.74", 106.7379928 -6.211082144 0.042414787
"_id" "soto-kudus%2C-soto-ayam-%26amp%3B-nasi-pindang_plaza-senayan_-6.23_106.80", 106.7989969 -6.225694167 0.046725248
"_id" "soto-kudus%2C-soto-ayam-%26amp%3B-nasi-pindang_plaza-bri-ii_-6.22_106.81", 106.8136847 -6.217476287 0.051006427
"_id" "soto-kudus%2C-soto-ayam-%26amp%3B-nasi-pindang_automall-indonesia_-6.23_106.81", 106.8096431 -6.225898946 0.053567221
"_id" "soto-kudus%2C-soto-ayam-%26amp%3B-nasi-pindang_menara-mulia_-6.22_106.82", 106.81656 -6.224232983 0.057448344
"_id" "nasi-gule-gandaria__-6.24_106.80", 106.795285 -6.244444863 0.061592999
"_id" "nasi-soto-monggo-mampir__-6.24_106.80", 106.7971516 -6.244479441 0.062329244
"_id" "nasi-soto-ayam-\"pak-min\"__-6.24_106.82", 106.8151546 -6.236743573 0.065276161
"_id" "nasi-soto-ayam-pak-min---santa__-6.24_106.81", 106.812959 -6.239508 0.066035611
"_id" "soto-mie-nasi-bogor__-6.23_106.83", 106.8322349 -6.234845139 0.076251787
"_id" "nasi-uduk-soto-ayam__-6.24_106.87", 106.8693781 -6.239089942 0.109671831
"_id" "soto-ayam-%2F-nasi-uduk-betawi__-6.28_106.71", 106.714092 -6.282785 0.112097201
"_id" "soto-minang-roda-jaya_ruko-tongkol-indah_-6.12_106.89", 106.889044 -6.119294471 0.13417281
"_id" "nasi-bebek-dan-soto-mas-muchlis_summarecon-kelapa-gading_-6.16_106.91", 106.9059021 -6.156281135 0.136471939
"_id" "nasi-liwet-%26-soto-kwali-kalimalang__-6.25_106.93", 106.9338112 -6.248527508 0.172293693
"_id" "soto-ayam-nasi-rames__-6.88_107.58", 107.5751638 -6.881692483 1.058802838
"_id" "nasi-liwet-soto-solo_rumah-mode_-6.88_107.60", 107.5998616 -6.882452292 1.078123028
"_id" "nasi-soto-ayam-madura__-6.91_107.57", 107.5749707 -6.912900474 1.079160684
"_id" "nasi-soto-mie__-6.89_107.60", 107.5969434 -6.890355658 1.080954023
"_id" "nasi-rames-soto-bandung-enjoi__-6.89_107.60", 107.5970721 -6.890504777 1.081148114
"_id" "nasi-soto-ayam__-6.91_107.58", 107.5769877 -6.913560825 1.081099449
"_id" "nasi-soto-ayam__-6.91_107.60", 107.5977552 -6.90656 1.092061283
"_id" "nasi-soto-ayam-madura__-6.89_107.62", 107.6157832 -6.888615935 1.094281476
"_id" "nasi-goreng-soto-ayam__-6.90_107.61", 107.6093245 -6.89662571 1.094431917
"_id" "nasi-soto-gulai-kambing__-6.90_107.61", 107.6090455 -6.900715755 1.096845722
"_id" "putra-bengawan-nasi-goreng-%26-soto__-6.89_107.62", 107.617187 -6.891298 1.097063729
"_id" "nasi-soto-ayam__-6.90_107.61", 107.6088095 -6.901163102 1.096953691
"_id" "nasi-uduk-%26amp%3B-soto-kikil-cak-khohar__-6.89_107.61", 107.6144958 -6.894765295 1.097201996
"_id" "nasi-soto-ayam__-6.90_107.62", 107.6204395 -6.900453028 1.105389179
"_id" "nasi-goreng-soto-ayam__-6.90_107.62", 107.6206326 -6.900303912 1.105442127
"_id" "nasi-soto-ayam-madura__-6.91_107.62", 107.6169634 -6.909279174 1.10839237
"_id" "nasi-soto_pasar-baru_-6.92_107.61", 107.605226 -6.923423387 1.108717834
"_id" "nasi-soto-ayam-madura_pasar-baru_-6.92_107.61", 107.6053333 -6.92348729 1.108840349
"_id" "nasi-soto-sarinah__-6.90_107.63", 107.631175 -6.897282 1.111636423
"_id" "nasi-uduk-soto__-6.89_107.64", 107.6361465 -6.893636262 1.113187903
"_id" "nasi-soto-ayam-madura__-6.91_107.63", 107.629376 -6.910677 1.118767984
"_id" "nasi-soto-ayam__-6.91_107.63", 107.629376 -6.910677 1.118767984
"_id" "nasi-uduk-soto__-6.94_107.62", 107.6248813 -6.93937772 1.133952371
"_id" "nasi-soto-ayam-khas-madura__-6.94_107.63", 107.625749 -6.940099 1.135077548
"_id" "nasi-uduk-%26amp%3B-soto__-6.96_107.64", 107.638936 -6.955310213 1.154967917
"_id" "nasi-soto-ayam_ruko-metro-trade-center_-6.94_107.66", 107.6600504 -6.940208438 1.161142923
"_id" "nasi-soto-ayam-khas-madura__-6.94_107.69", 107.6948118 -6.937141164 1.185994885
"_id" "nasi-soto-ayam-khas-madura-cak-nonk__-6.93_107.72", 107.7156472 -6.932668019 1.199509086
"_id" "nasi-gandul__-7.43_109.24", 109.2391822 -7.425856643 2.756884824
Look again the term in the query
"$maxDistance" : 0.053980478460939611
Go figure.
By the way $maxDistance is DEFINETLY used properly. Reducing it does lead to less results. The issue seems to come from the fact that whatever formula mongodb use to compute distance is inaccurate.
I answered the same post you made on stackexchange:
https://dba.stackexchange.com/questions/23869/nearsphere-returns-too-many-data-what-am-i-missing-am-i-wrong-is-it-a-bug-d
Does that help?
Thanks,
andrew