MongoDB sort does not work - mongodb

since this morning (I think) I can't sort my collection. The collection has 26944 objects inside (it is currently my biggest - but that cant be the reason right?).
So what i'm doing:
myCollection.find().sort({ _id: 1 })
this works great and without any problem!
but:
myCollection.find().sort({ xxx: 1 })
each other case don't work, xxx means any other key on my object it does not matter which I take...
for example:
myCollection.find({modified: { $exists : true } })
Returns an result with 26944 Objects,
myCollection.find({modified: { $exists : true } }).sort({"modified":-1})
will return 0 Objects.
Did I something wrong?
Maybe I had crashed my collection? Did somebody know what could do in this case? (excepts dropping the collection)
Example Object:
{
"_id": ObjectId("55071e25760e250d050ed8d5"),
"sysModified": new Date("2015-03-15T21:10:12+0100"),
"created": new Date(1426529829922),
"modified": new Date(1426528563945),
"payments": [
],
"orderItems": [
{
"orderId": 'xxxxx',
"itemId": 'xxxxx',
"ean": "XXXXX"
"quantity": 1,
"name": "xxxxxxx",
"vat": 19,
"price": 29.989999999999998437,
"currency": "EUR",
"_id": ObjectId("5507365c89866d820dcef7e0"),
},
{
"orderId": 'xxxxx',
"itemId": 'xxxxx',
"ean": "XXXXX"
"quantity": 1,
"name": "xxxxxxx",
"vat": 19,
"price": 29.989999999999998437,
"currency": "EUR",
"_id": ObjectId("5507365c89866d820dcef7e1"),
}
],
"orderData": {
"orderId": XXXXXXXXX,
"type": "order",
"status": "XXXXXXXXX",
"timestamp_php": XXXXXXXXX,
"customer": XXXXXXXXX,
...
},
"orderDeliveryAddress": {
"customer": xxxxxxxxxxx,
"company": "",
"additional": "",
"firstName": "xxxxxxxxxxx",
"surname": "xxxxxxxxxxx",
"street": "xxxxxxxxxxx",
"houseNumber": "xxxxxxxxxxx",
"zip": "xxxxxxxxxxx",
"city": "xxxxxxxxxxx",
"iso2": "xxxxxxxxxxx",
"phone": "xxxxxxxxxxx",
"fax": "xxxxxxxxxx",
"email": "xxxxxxxxxxx",
},
"orderCustomerAddress": {
"customer": xxxxxxxxxxx,
"company": "",
"additional": "",
"firstName": "xxxxxxxxxxx",
"surname": "xxxxxxxxxxx",
"street": "xxxxxxxxxxx",
"houseNumber": "xxxxxxxxxxx",
"zip": "xxxxxxxxxxx",
"city": "xxxxxxxxxxx",
"iso2": "xxxxxxxxxxx",
"phone": "xxxxxxxxxxx",
"fax": "xxxxxxxxxx",
"email": "xxxxxxxxxxx",
},
"__v": 1
}

It is possible that your collection is to big. If you try so sort on a key, that has no index this can result in an error if the resultset is to big. The error should look like this:
error: {
"$err" : "too much data for sort() with no index.
add an index or specify a smaller limit",
"code" : 10128
}
What you can do is add an index to your key you want to sort by:
db.myCollection.ensureIndex({"modified":-1})
Or you reduce the resultset before sorting:
myCollection.find({modified: { $exists : true } }).limit(10).sort({"modified":-1})

Related

Find Object within an Array that is within an object also within an Array

I've been struggling with the following Mongo document:
{
"name": "Fire Name",
"address": "123 Somestreet Ave",
"city": "Boston",
"state": "MA",
"zip": "02109",
"dispatchReference": "123codefromdispatch",
"created": {
"$date": "2021-02-26T12:30:41Z"
},
"lastPar": {
"$date": "2021-02-26T22:30:41Z"
},
"latitude": "-83.691407",
"longitude": "141.338391",
"par": 3,
"vehicles": [
{
"_id": "60397691c09c2fd299c40420",
"hidden": false,
"vehicleName": "Updated",
"vehicleNumber": 20,
"vehicleStatus": "Enroute",
"latitude": "-83.691407",
"longitude": "141.338391",
"par": 6,
"lastPar": "2021-02-26T22:30:41+00:00",
"members": [
{
"_id": "60397b14f2a2b10978693a47", <---- find Member with this ID
"hidden": false, <----- update this property
"rank": "firefighter",
"dateOfRank": "2021-02-26T22:49:56+00:00",
"role": "hose",
"firstName": "Reyna",
"lastName": "Casey",
"dateOfBirth": "1992-02-26T22:49:56+00:00",
"sex": "male",
"age": 29,
"dateOfExperience": 5,
"departmentLocation": "975 Pine Street, Gasquet, Montana, 1843",
"lastIncidentID": "60397b14095d4f4313fbf716",
"bpm": 120,
"vomax": "33.1",
"temp": "104.69",
"latitude": "-81.393671",
"longitude": "-78.26867",
"scba": {
"maskStatus": false,
"oxygenLevel": "low"
}
I'm attempting to write a Mongo query that when given the member._id, will update that specific member's hidden property from false to true. So I need to tunnel down into my vehicles array of objects, and find the member within the members array with the matching _id.
I suspect it has something to do with the $[] operator but I'm not having any luck.
Try this:
db.testcollection.updateOne(
{
// Specify some condition related to "vehicles" array.
"vehicles.members._id": ObjectId("60397b14f2a2b10978693a47")
},
{
$set: {
"vehicles.$.members.$[obj].hidden": true
}
},
{
arrayFilters: [
{
"obj._id": ObjectId("60397b14f2a2b10978693a47")
}
]
}
);

Loopback 3: Multiple HasOne relation on one model

So, I opened an issue here, coz in my opinion it should work as I think... but might be wrong so looking for another way
So, pretty much I have two models, Wedding and Person. The Wedding one has these relations set:
"people": {
"type": "hasMany",
"model": "person",
"foreignKey": "",
"options": {
"nestRemoting": true
}
},
"partner1": {
"type": "hasOne",
"model": "person",
"foreignKey": ""
},
"partner2": {
"type": "hasOne",
"model": "person",
"foreignKey": ""
}
And one of my wedding documents looks like this (I am using mongoDB if you cannot tell):
{
"_id": "5de78c76f89d1a8ad4091ca5",
"date": "2019-12-04T10:37:42.000Z",
"userId": "5de78c76f89d1a8ad4091ca4",
"created": "2019-12-04T10:37:42.720Z",
"partner1Id": "5de78c77f89d1a8ad4091ca6",
"partner2Id": "5de78c77f89d1a8ad4091ca7"
}
So, when I set include filter and do:
{ "include": ["partner1", "partner2"]}
in my loopback API explorer on
http://localhost:3000/api/weddings/5de78c76f89d1a8ad4091ca5
I get:
{
"date": "2019-12-04T10:37:42.000Z",
"id": "5de78c76f89d1a8ad4091ca5",
"userId": "5de78c76f89d1a8ad4091ca4",
"created": "2019-12-04T10:37:42.720Z",
"partner1Id": "5de78c77f89d1a8ad4091ca6",
"partner2Id": "5de78c77f89d1a8ad4091ca7",
"partner1": {
"id": "5de78c77f89d1a8ad4091ca7",
"fullName": "Jessica Alba",
"spouse": "spouse2",
"contacts": [],
"verified": false,
"created": "2019-12-04T10:37:43.292Z",
"updated": "2019-12-04T10:37:43.292Z",
"userId": "5de78c76f89d1a8ad4091ca4",
"weddingId": "5de78c76f89d1a8ad4091ca5"
},
"partner2": {
"id": "5de78c77f89d1a8ad4091ca7",
"fullName": "Jessica Alba",
"spouse": "spouse2",
"contacts": [],
"verified": false,
"created": "2019-12-04T10:37:43.292Z",
"updated": "2019-12-04T10:37:43.292Z",
"userId": "5de78c76f89d1a8ad4091ca4",
"weddingId": "5de78c76f89d1a8ad4091ca5"
}
}
But, I am expecting this:
{
"date": "2019-12-04T10:37:42.000Z",
"id": "5de78c76f89d1a8ad4091ca5",
"userId": "5de78c76f89d1a8ad4091ca4",
"created": "2019-12-04T10:37:42.720Z",
"partner1Id": "5de78c77f89d1a8ad4091ca6",
"partner2Id": "5de78c77f89d1a8ad4091ca7",
"partner1": {
"id": "5de78c77f89d1a8ad4091ca6",
"fullName": "Michael Knight",
"spouse": "spouse1",
"contacts": [],
"verified": false,
"created": "2019-12-04T10:37:43.292Z",
"updated": "2019-12-04T10:37:43.292Z",
"userId": "5de78c76f89d1a8ad4091ca4",
"weddingId": "5de78c76f89d1a8ad4091ca5"
},
"partner2": {
"id": "5de78c77f89d1a8ad4091ca7",
"fullName": "Jessica Alba",
"spouse": "spouse2",
"contacts": [],
"verified": false,
"created": "2019-12-04T10:37:43.292Z",
"updated": "2019-12-04T10:37:43.292Z",
"userId": "5de78c76f89d1a8ad4091ca4",
"weddingId": "5de78c76f89d1a8ad4091ca5"
}
}
Any ideas as of why? why do I get the same two records for partner1 and partner2?
Instead of using "hasOne", use "belongsTo".

uber RUSH API sandbox deliveries is_fragile value incorrect, bug?

While experimenting with the uber deliveries API sandbox I noticed that when I POST to https://sandbox-api.uber.com/v1/deliveries to create delivery of a new item with item[]."is fragile": true, that the response from the sandbox incorrectly shows item[]."is fragile": false. At least I think this is incorrect, I didn't see it listed as a known limitation of the sandbox. Is this a bug?
More information:
OS: Ubuntu 16.04.1 LTS
Client: Postman 4.9.0
POST request to URL https://sandbox-api.uber.com/v1/deliveries
POST /v1/deliveries HTTP/1.1
Host: sandbox-api.uber.com
Authorization: [redacted]
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: [redacted]
{
"items": [
{
"title": "Fragile Item",
"quantity": 1,
"price": 30,
"is_fragile": true,
"currency_code": "USD",
}
],
"dropoff": {
"location": {
"address": "530 W 113th Street",
"address_2": "Floor 2",
"city": "New York",
"country": "US",
"postal_code": "10025",
"state": "NY"
},
"contact": {
"first_name": "Alice",
"last_name": "Dropoff",
"email": "tomb#cryptocracy.net",
"phone": {
"number": "+19177447934",
"sms_enabled": "true",
},
}
},
"pickup": {
"location": {
"address": "636 W 28th Street",
"address_2": "Floor 2",
"city": "New York",
"country": "US",
"postal_code": "10001",
"state": "NY"
},
"contact": {
"first_name": "Bob",
"last_name": "Pickup",
"email": "tomb#cryptocracy.net",
"phone": {
"number": "+19177447934",
"sms_enabled": "true",
},
},
},
}
Response from the sandbox:
{
"status": "processing",
"dropoff": {
"eta": 12,
"signature_required": false,
"contact": {
"first_name": "Alice",
"last_name": "Dropoff",
"send_sms_notifications": true,
"send_email_notifications": true,
"phone": {
"sms_enabled": true,
"number": "+19177447934"
},
"email": "tomb#cryptocracy.net"
},
"special_instructions": "",
"location": {
"city": "New York",
"country": "US",
"longitude": -73.963863,
"state": "NY",
"postal_code": "10025",
"address_2": "Floor 2",
"address": "530 W 113th Street",
"latitude": 40.805264
},
"signature_image": {
"url": "",
"expires_at": "-62135596800"
},
"courier_notes": {}
},
"fee": 5,
"quote_id": "c7e135da-957e-40b7-a2c5-5d468dc1d686",
"courier": null,
"items": [
{
"weight": 0,
"title": "Bottle 3",
"price": 30,
"is_fragile": false,
"height": 0,
"width": 0,
"length": 0,
"currency_code": "USD",
"quantity": 1
}
],
"created_at": 1480961485,
"delivery_id": "21b1b8de-2cea-4bc4-a316-2fd7598787c7",
"pickup": {
"eta": 7,
"signature_required": false,
"contact": {
"first_name": "Bob",
"last_name": "Pickup",
"send_sms_notifications": true,
"send_email_notifications": true,
"phone": {
"sms_enabled": true,
"number": "+19177447934"
},
"email": "tomb#cryptocracy.net"
},
"special_instructions": "",
"location": {
"city": "New York",
"country": "US",
"longitude": -74.0064109,
"state": "NY",
"postal_code": "10001",
"address_2": "Floor 2",
"address": "636 W 28th Street",
"latitude": 40.7527293
},
"signature_image": {
"url": "",
"expires_at": "-62135596800"
},
"courier_notes": {}
},
"order_reference_id": "",
"tracking_url": "https://api.uber.com/v1/sandbox/map",
"currency_code": "USD"
}
This seems to be a bug in the Uber sandbox environment for the Deliveries API.

How JSON format for calling Checking out REST Api of Broadleaf commerce looks like

I have followed setting up Broadleaf to make it running by following its documentation (http://docs.broadleafcommerce.org/current/REST-Tutorials.html). I wanted to do checking out the cart using REST Api; that's, /cart/checkout. Therefore, I looked inside the code in order to understand how the JSON format being sent will look alike. By looking through the code, I found that it is required to pass the JSON data as shown following:
{
"paymentInfo": {
"id": ,
"orderId": ,
"type": ,
"address": {
"id":
"firstname":
"lastname":
"addressLine1":
"addressLine2":
"city":
"state":
"country":
"postalCode":
},
"phone": "",
"additionalFields": "",
"amount": "",
"amountItems": "",
"customerIpAddress": "",
"referenceNumber": ""
},
"referenced": {
"id": "",
"referenceNumber": "",
"type": "",
"pan": "",
"cvvCode:" "",
"expirationMonth": "",
"expirationYear": "",
"accountNumber": "",
"routingNumber": "",
"pin": ""
}
}
However, I have no idea such the JSON data looks like. Therefore, if anyone who has ever used the api, please help me by showing an example of data in order to make the request. Looking forward to the answers.
Thanks in advance.
All of our REST APIs are exposed through a 'wrapper' concept. For instance, there is a CustomerWrapper, OrderWrapper, etc. These wrappers define which properties are serialized back and forth with the REST APIs.
For your specific case, you should look at PaymentReferenceMapWrapper.
{
"id": 1751,
"status": "IN_PROCESS",
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"totalShipping": {
"amount": "0.00",
"currency": "INR"
},
"subTotal": {
"amount": "860.00",
"currency": "INR"
},
"total": {
"amount": "860.00",
"currency": "INR"
},
"customer": {
"id": 2600
},
"orderItems": [
{
"id": 1752,
"name": "abc",
"quantity": 2,
"retailPrice": {
"amount": "430.00",
"currency": "INR"
},
"salePrice": {
"amount": "430.00",
"currency": "INR"
},
"orderId": 1751,
"categoryId": 10300,
"skuId": 10212,
"productId": 10212,
"isBundle": false,
"orderItemPriceDetails": [
{
"id": 1752,
"totalAdjustmentValue": {
"amount": "0.00",
"currency": "INR"
},
"totalAdjustedPrice": {
"amount": "860.00",
"currency": "INR"
},
"quantity": 2,
"adjustments": []
}
],
"isDiscountingAllowed": true
}
],
"fulfillmentGroups": [
{
"id": 1502,
"orderId": 1751,
"total": {
"amount": "860.00",
"currency": "INR"
},
"fulfillmentGroupItems": [
{
"id": 1752,
"fulfillmentGroupId": 1502,
"orderItemId": 1752,
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"quantity": 2,
"totalItemAmount": {
"amount": "860.00",
"currency": "INR"
}
}
]
}
],
"payments": [
{
"id": 601,
"orderId": 1751,
"type": "COD",
"amount": "860.00",
"currency": "INR",
"gatewayType": "Passthrough",
"transactions": [
{
"id": 601,
"orderPaymentId": 601,
"type": "AUTHORIZE_AND_CAPTURE",
"success": true,
"amount": "860.00",
"currency": "INR"
}
]
}
]
}
This is the same json you will get from /cart?customerId="" with method GET after successfully executing /cart/checkout/payment

mongo search not working on keywords

{
"_id": ObjectId("4ed8d496c605da94400001e4"),
"status": 1,
"user": {
"uid": 1
},
"nid": 10582,
"form": {
"your-name": "Bob Smith",
"description": "",
"photo": "",
"address": "123 Turk Hill Rd",
"city": "",
"zip": "14450"
},
"location": {
"address": "123 Turk Hill Rd",
"city": "",
"zip": "14450",
"geo_lat": 43.0329181,
"geo_lng": -77.4391148,
"address_confirmed": "123 Turk Hill Rd, Victor, NY 14564, USA",
"address_status": 200,
"accuracy": 8
},
"keywords": {
"0": "bob",
"1": "smith",
"2": "",
"4": "123",
"5": "turk",
"6": "hill",
"7": "rd",
"9": "14450"
},
"time": ISODate("2011-12-02T13: 37: 26.0Z")
Search:
{
nid: 10582,
keywords: {"$in": ['turk']}
}
Results: none!
What am I doing wrong?
Answer is simple: because of keywords is not an array. To search on keywords you need to change document structure as follow:
{
...
"keywords": [
"bob",
"smith",
"123",
"turk",
"hill",
"rd",
"14450"
],
...
}
It usually happens when you from driver serialize dictionary. In current moment there is no way to search in such structure. Simple use arrays instead of dictionaries. Or you can convert dictionary to array before serialize document and viсe versa when deserialize document.