I want to post associative array with retrofit on android but I can't figure it out yet.Below is the expected request to server using post
{
"que_id": "4",
"que_assistants": [
14
],
"opening_cash_lines": [
{
"denomination": "1000",
"count": 5
},
{
"denomination": "500",
"count": "2"
}
]
}
Someone help me out on this
Related
I have a problem to writing a mongodb query to nested updating an array of objects.
My current document in the collection is like this:
{
"_id": 1,
"data": {
"arr_1": [
{
"inner_arr_1": [
{
"aid": "111",
"ans": "def"
},
{
"aid": "222",
"ans": "def"
},
],
"inner_arr_2": [
{
"aid": "333",
"ans": "def"
},
{
"aid": "444",
"ans": "def"
},
],
"inner_arr_3": [
{
"aid": "555",
"ans": "def"
},
{
"aid": "666",
"ans": "def"
},
]
},
]
},
"name": "John"
}
I want to write an API endpint by express in nodejs to nested update this document.
The post body of the endpoint is like:
req.body = {
"_id": 1,
"data": {
"arr_1": [
{
"inner_arr_1": [
{
"aid": "111",
"ans": "new val"
}
],
"inner_arr_3": [
{
"aid": "666",
"ans": "new val"
}
]
},
]
}
}
Anyone can help me to write a query to solve this problem?
Thank you.
I have data something like below:
{
"_id": "60708607143b058e101fc189",
"orders": {
"userID": "606eaa5cf67ac70cfa347fcd",
"order": [
{
"productIDs": [ "606f1f37006513258c8b59b9" ],
"vendorID": "60641cf597aed2a9a2971a3f",
"id": "60708607143b058e101fc18a"
},
{
"productIDs": [ "606f1fec006513258c8b59ba", "606f2bb2006513258c8b59bd" ],
"vendorID": "60642991015028ba0a6ce72c",
"id": "60708607143b058e101fc18b"
}
]
},
}
Is there a way to find any given vendorID in this record using nodejs and mongoose?
If you are logged in as a vendor, then you can send the vendor_id in the body of the request. To filter all orders associated to that particular vendor, you can try this:
Model.find({"orders.order":
{
"$elemMatch": {
"vendorID": req.body.vendor_id
}
}
});
I have the following view in CouchDB that is reduced via _count:
function (doc) {
if (doc.type === "signature") {
emit([doc.worksite_id, doc.uid, doc.timestamp], doc._id);
}
}
There are cases where rather than using group_level=2 in my query to get my count values sorted by doc.worksite_id and doc.uid pairs (as shown below)...
{
"rows": [
{
"key": [
"worksite-1",
"id-1"
],
"value": 2
},
{
"key": [
"worksite-2",
"id-1"
],
"value": 1
},
{
"key": [
"worksite-2",
"id-2"
],
"value": 26
}
]
}
...I, instead, need to get count values sorted strictly by doc.uid, with an example of something similar to the following:
{
"rows": [
{
"key": [
"id-1"
],
"value": 3
},
{
"key": [
"id-2"
],
"value": 26
}
]
}
Is there an efficient way to do this based on the current view I'm querying from? And if not, what is the most efficient way to do this?
Cloudant is returning error message:
{"error":"invalid_key","reason":"Invalid key use-index for this request."}
whenever I try to query against an index with the combination operator, "$or".
A sample of what my documents look like is:
{
"_id": "28f240f1bcc2fbd9e1e5174af6905349",
"_rev": "1-fb9a9150acbecd105f1616aff88c26a8",
"type": "Feature",
"properties": {
"PageName": "A8",
"PageNumber": 1,
"Lat": 43.051523,
"Long": -71.498852
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-71.49978935969642,
43.0508382914137
],
[
-71.49978564033566,
43.052210148524
],
[
-71.49791499857444,
43.05220740550381
],
[
-71.49791875962663,
43.05083554852429
],
[
-71.49978935969642,
43.0508382914137
]
]
]
}
}
The index that I created is for field "properties.PageName", which works fine when I'm just querying for one document, but as soon as I try for multiple ones, I would receive the error response as quoted in the beginning.
If it helps any, here is the call:
POST https://xyz.cloudant.com/db/_find
request body:
{
"selector": {
"$or": [
{ "properties.PageName": "A8" },
{ "properties.PageName": "M30" },
{ "properties.PageName": "AH30" }
]
},
"use-index": "pagename-index"
}
In order to perform an $or query you need to create a text (full text) index, rather than a json index. For example, I just created the following index:
{
"index": {
"fields": [
{"name": "properties.PageName", "type": "string"}
]
},
"type": "text"
}
I was then be able to perform the following query:
{
"selector": {
"$or": [
{ "properties.PageName": "A8" },
{ "properties.PageName": "M30" },
{ "properties.PageName": "AH30" }
]
}
}
I'm trying to query documents in a Cloudant.com database (CouchDB). The two following query requests work fine separately:
{ "selector": { "some_field": "value_1" } }
{ "selector": { "some_field": "value_2" } }
Cloudant's documentation seems to indicate I should be able to combine those two queries into a single HTTP request as follows:
{ "selector": { "$or": [ { "some_field": "value_1" },
{ "some_field": "value_2" } ] } }
But when I try that I receive the following response:
{"error":"no_usable_index",
"reason":"There is no operator in this selector can used with an index."}
Can someone tell me what I need to do to get this to work?
There doesn't seem to be a way to achieve this with Cloudant Query at the moment. However, you can use a view query instead using the index created with Cloudant Query. Assuming the index is in a design document named ae97413b0892b3738572e05b2101cdd303701bb8:
curl -X POST \
'https://youraccount.cloudant.com/db/_design/ae97413b0892b3738572e05b2101cdd303701bb8/_view/ae97413b0892b3738572e05b2101cdd303701bb8?reduce=false&include_docs=true' \
-d '
{
"keys":[
["value_1"],
["value_2"]
]
}'
This will give you a response like this:
{
"total_rows": 3,
"offset": 1,
"rows": [
{
"id": "5fcec42ba5cad4fb48a676400dc8f127",
"key": [
"abc"
],
"value": null,
"doc": {
"_id": "5fcec42ba5cad4fb48a676400dc8f127",
"_rev": "1-0042bf88a7d830e9fdb0326ae957e3bc",
"some_field": "value_1"
}
},
{
"id": "955606432c9d3aaa48cab0c34dc2a9c8",
"key": [
"ghi"
],
"value": null,
"doc": {
"_id": "955606432c9d3aaa48cab0c34dc2a9c8",
"_rev": "1-68fac0c180923a2bf133132301b1c15e",
"some_field": "value_2"
}
}
]
}