How to provide custom IDs during JSON import in Firebase Database? - firebase-realtime-database

How can I set the ID of the record or doc in the Firebase Database when I use the JSON import functionality?
When I import the file it creates sequential IDs (0, 1, 2 etc), but I would like to specify an ID so its easier to retrieve the record.
Below is my sample JSON data:
[
{
"GameID": 2234567890,
"GameName": "Team 3 vs Team 2",
"GameLocation": "Rink 4 Hockey Town",
"TypeOfGame": "Tournament Round Robin",
"HomeTeam": {
"Name": "Team 1",
"ImageUrl": "My Image URL 1",
"Level": "16AAA",
"Country": "USA"
}
}, {
"GameID": 1234567890,
"GameName": "Team 1 vs Team 2",
"GameLocation": "Rink 1 Hockey Town",
"TypeOfGame": "Tournament Round Robin",
"HomeTeam": {
"Name": "Team 1",
"ImageUrl": "My Image URL 1",
"Level": "16AAA",
"Country": "USA"
}
}
]

There is no way in which you can import a JSON file and generate a custom Id in the same time. You are getting (0, 1, 2 etc) as Ids because there is no unique identifier between those objects and Firebase sees all those records as a list, and therefor provides those ids for you.
To achieve what you want, you need to add that data programmatically using the push() function provided by Firebase for each record. This method generates a unique id which easy to be used in the future.

[ {
"1234567890" : {
"GameID" : 1234567890,
"GameLocation" : "Rink 1 Hockey Town",
"GameName" : "Team 1 vs Team 2",
"HomeTeam" : {
"Country" : "USA",
"ImageUrl" : "My Image URL 1",
"Level" : "16AAA",
"Name" : "Team 1"
},
"TypeOfGame" : "Tournament Round Robin"
},
"2234567890" : {
"GameID" : 2234567890,
"GameLocation" : "Rink 4 Hockey Town",
"GameName" : "Team 3 vs Team 2",
"HomeTeam" : {
"Country" : "USA",
"ImageUrl" : "My Image URL 1",
"Level" : "16AAA",
"Name" : "Team 1"
},
"TypeOfGame" : "Tournament Round Robin"
}
} ]

Related

Couchbase N1QL query running, but no data retrieved (wrong query i guess)

I am trying to retrieve data from 2 buckets, no error but nothing shows up (I do have documents I need in these buckets).
1st bucket: a_bucket
here is the document I am interested in (I do have 3 different docs)
author_ID document:
{
"author_ID": 1,
"profil_creation_date": "2017/01/01/01:23:05/+5",
"prefix": "Mr.",
"first_name": "Dylan",
"middle_name_s": "Alfred",
"last_name": "Kerr",
"date_of_birth": "1974/01/02",
"sex": "M",
"marital_status": "Single",
"mobile_phone": "(860) 231-3336",
"address": [
{
"address_1": {
"address_ID": 1,
"home_address": "338 Counts Lane",
"city": "West Hartford",
"province/state": "CT",
"postal_code": "06105"
}
},
{
"address_2": {
"address_ID": 2,
"work_address": "977 Copperhead Rd",
"city": "Newington",
"province/state": "CT",
"postal_code": "06111"
}
}
]
}
2nd bucket: b_bucket
here are the 2 docs I am interested in:
p_output_ID document:
{
"p_output_ID": 1,
"author_ID": 2,
"overall_score": 4.41,
"status": {
"r_status_first": "TRUE",
"r_status_second": "FALSE",
"r_status_third": "YES",
"y_status_second": "TRUE",
"y_status_third": "FALSE",
"g_status_third": "TRUE"
}
}
timing_ID document:
{
"timing_ID": 1,
"p_output_ID": 1,
"author_ID": 1,
"date_and_time": "2017-06-06/23:45:25.25/+5",
"time_in_seconds": 12525,
"incremental_time_in_seconds": "time_in_seconds",
"current_state_and_duration": {
"state": "RED",
"duration_in_seconds": 33333
}
}
my goal is to grab these informations in one query ():
prefix, first_name, middle_name_s, last_name (from author_ID document in a_bucket)
overall_score (from p_output_ID document in b_bucket)
date_and_time, state (from timing_ID document in b_bucket)
Here is my query:
select p2.current_state_and_duration.state, p1.overall_score, p2.date_and_time
from proc_data_bucket p1 USE KEYS "p_output_ID"
JOIN proc_data_bucket p2 ON KEYS "author_ID";
The syntax is OK, but I am getting no data
Please help me with that...
CREATE INDEX ix1 ON b_bucket(timing_ID);
SELECT p1.prefix, p1.first_name, p1.middle_name_s, p1.last_name,
p2.date_and_time,p2.state,
p3.overall_score
FROM b_bucket p2
JOIN a_bucket p1 ON KEYS ("author_" || TO_STRING(p2.author_ID))
JOIN b_bucket p3 ON KEYS ("p_output_" || TO_STRING(p2.p_output_ID))
WHERE p2.timing_ID BETWEEN 10 AND 50;

Invalid Reference Id : Line.SalesItemLineDetail.ItemRef

I have tried to create sales receipt in quickbook using quickbook api. My most of sales receipt has successfully created at quick book without any issue. But quickbook api throw exception for one order. I have got below error:
{
"Fault": {
"Error": [
{
"Message": "Invalid Reference Id",
"Detail": "Invalid Reference Id : Line.SalesItemLineDetail.ItemRef",
"code": "2500",
"element": "Line.SalesItemLineDetail.ItemRef"
}
],
"type": "ValidationFault"
},
"time": "2017-05-04T03:32:18.942-07:00"
}
Below are json that I have tried with API :
{
"SalesReceiptEx":null,
"AutoDocNumber":null,
"CustomerRef":{
"name":"Alexander",
"type":null,
"value":"325"
},
"CustomerMemo":null,
"BillAddr":{
"Id":"1",
"Line1":"Alexander Kryukov",
"Line2":"22 Chester Terrace",
"Line3":"London",
"Line4":"United Kingdom,GB",
"Line5":"NW1 4ND",
"City":null,
"Country":null,
"CountryCode":null,
"CountrySubDivisionCode":null,
"PostalCode":null,
"PostalCodeSuffix":null,
"Lat":null,
"Long":null,
"Tag":null,
"Note":null
},
"ShipAddr":{
"Id":"2",
"Line1":"Alexander Kryukov",
"Line2":"22 Chester Terrace",
"Line3":null,
"Line4":null,
"Line5":null,
"City":"London",
"Country":"United Kingdom",
"CountryCode":null,
"CountrySubDivisionCode":"GB",
"PostalCode":"NW1 4ND",
"PostalCodeSuffix":null,
"Lat":null,
"Long":null,
"Tag":null,
"Note":null
},
"RemitToRef":null,
"ClassRef":null,
"SalesTermRef":null,
"DueDate":null,
"SalesRepRef":null,
"PONumber":null,
"FOB":null,
"ShipMethodRef":null,
"ShipDate":null,
"TrackingNum":null,
"GlobalTaxCalculation":null,
"TotalAmt":"136.90000",
"HomeTotalAmt":null,
"ApplyTaxAfterDiscount":null,
"TemplateRef":null,
"PrintStatus":null,
"EmailStatus":null,
"BillEmail":{
"Id":null,
"Address":"sash_300#hotmail.com",
"Default":null,
"Tag":null
},
"ARAccountRef":null,
"Balance":null,
"HomeBalance":null,
"FinanceCharge":null,
"PaymentMethodRef":null,
"PaymentRefNum":null,
"PaymentType":null,
"CheckPayment":null,
"CreditCardPayment":null,
"DepositToAccountRef":{
"name":"Business Bank Account HSBC",
"type":null,
"value":58
},
"DeliveryInfo":null,
"DiscountRate":null,
"DiscountAmt":null,
"GovtTxnRefIdentifier":null,
"DocNumber":1163080716,
"TxnDate":"2017-05-04",
"DepartmentRef":null,
"CurrencyRef":null,
"ExchangeRate":null,
"PrivateNote":null,
"TxnStatus":null,
"LinkedTxn":null,
"Line":[
{
"Id":1,
"LineNum":1,
"Description":"Flowery Floater Birthday Number",
"Amount":"43.29167",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Flowery Floater Birthday Number",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"43.29167",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":2,
"LineNum":2,
"Description":"Custom Product",
"Amount":"37.50000",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Custom Product",
"type":null,
"value":"10"
},
"ClassRef":null,
"UnitPrice":"3.75000",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"10",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":3,
"LineNum":3,
"Description":"Additional Delivery Charge",
"Amount":"30.00000",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Additional Delivery Charge",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"30.00000",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":4,
"LineNum":4,
"Description":"Shipping Cost",
"Amount":"3.29167",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Shipping Cost",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"3.29167",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
}
],
"TxnTaxDetail":null,
"TxnSource":null,
"TaxFormType":null,
"TaxFormNum":null,
"TransactionLocationType":null,
"Id":null,
"SyncToken":null,
"MetaData":null,
"CustomField":null,
"AttachableRef":null,
"domain":null,
"status":null,
"sparse":null
}
Could anyone suggest, what is actual problem with this request?
The error message indicates exactly what the problem is:
"Message": "Invalid Reference Id",
"Detail": "Invalid Reference Id : Line.SalesItemLineDetail.ItemRef",
"code": "2500",
"element": "Line.SalesItemLineDetail.ItemRef"
Based on your request, it looks like you're just inventing these values, rather than actually querying these from QuickBooks.
I'm assuming this because in one place your item is called one thing, and in another it's called something totally different:
"ItemRef":{
"name":"Shipping Cost",
"type":null,
"value":"1"
},
Even though the Id values are identical (1) in both cases:
"ItemRef":{
"name":"Additional Delivery Charge",
"type":null,
"value":"1"
},
You can't just invent these numbers. They are Id values that you have to query from Intuit.
https://developer.intuit.com/docs/api/accounting/item
Query them by doing:
SELECT * FROM Item
I got this error when trying to submit an invoice line item with an ID outside the range of available IDs in the QuickBooks Sandbox.
For example, my production app has ~50 categories and the Sandbox only has ~20, so trying to use ID 40 in the Sandbox caused this error.
To resolve the issue I simply reduced the ID number for testing.

Adding Implementation Notes and Description to Swagger UI

I am attempting to add Implementation Notes and Description to my Swagger UI. However, neither show up on the UI when implemented as below:
{
"swagger" : "2.0",
"info" : {
"description" : "The definition of the Rest API to service plugin over https on port 9443.",
"version" : "1.0",
"title" : "Plugin Rest API",
"contact" : {
"name" : "John Doe",
"email" : "john.doe#gmail.com"
}
},
"basePath" : "/service",
"tags" : [ {
"name" : "service"
} ],
"schemes" : [ "https" ],
"paths" : {
"/entry" : {
"get" : {
"notes" : "This is a note",
"method" : "get",
"tags" : [ "service" ],
"summary" : "Get an entry by first name and last name",
"description" : "This is a description",
"operationId" : "getEntry",
"produces" : [ "application/xml", "application/json" ],
"parameters" : [ {
"name" : "first",
"in" : "query",
"description" : "The first name",
"required" : true,
"type" : "string"
}, {
"name" : "last",
"in" : "query",
"description" : "The last name",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "Matching entry, or entries, if any, were returned",
"schema" : {
"$ref" : "#/definitions/Service"
}
}
}
},
I am not sure what I am doing wrong in my code. I've tested it on various sample swagger.json files and I cannot seem to get it to work.
notes is not a swagger field. See the documentation
Your description field is written twice, so the first one has been overridden.
you can add implementation notes using notes tag in #ApiOperation annotation as shown below,
#ApiOperation(notes = "Your Implementation Notes will show here[![enter image description here][1]][1]", value = "Add Customer Payment Details and Generate Payment Link through Batch.", nickname = "insertPaymentBatch", tags =
"Insert Payment" )

Neo4j Cypher: Importing nested collection by getting Error: Unable to deserialize request: Unexpected character code 99

I have nested collection and I add "Data" then foreach "Data" I add its own "Tags". I found unwind for "Data" with foreach for "Tags".
I wanna add person which I import its info from outside of collection manually.
I execute below Cypher query by statements:
I have imitated from:
Cypher Import Statement
AND
Cypher Unwind
I checked my json via enter link description here And it is validated.
{ "statements": [ { "statement": " WITH { "categories": [ {"dataid" : "11" , "dataname" : "data1" , "datalanguage" : "en" , "datatype" : "type1" ,"content" : "content1" , "tags" : [{"myid" : "11" , "tagid" : 10 , "tagname" : "tag1" }] } , {"dataid" : "22" , "dataname" : "data2" , "datalanguage" : "en" , "datatype" : "type2" ,"content" : "content2" , "tags" : [{"myid" : "22" , "tagid" : 20 , "tagname" : "tag2" }] } ] } AS document UNWIND document.categories AS category MERGE (dt:Data {name: category.dataname}) ON CREATE SET dt.id = category.dataid , dt.type = category.datatype , dt.language = category.datalanguage , dt.content = category.datacontent MERGE (p:Person { name : 'Mahsa' , lastname : 'Mahsa' } ) ON CREATE SET p.id =1 MERGE (p)-[r:owner]->(dt) FOREACH (mytag IN category.tags | MERGE (t:Tag {name: mytag.tagname}) ON CREATE SET t.id = mytag.tagid MERGE (dt)-[r2:tagged { Freq : 12 ]->(t) )" } ] }
But it returns as result: (I checked many times for "Unexpected character" but I could not find )
{"results":[],"errors":[{"code":"**Neo.ClientError.Request.InvalidFormat**","message":"**Unable to deserialize request: Unexpected character ('c' (code 99)): was expecting comma to separate OBJECT entries**\n at [Source: HttpInputOverHTTP#132e16b; line: 1, column: 48]"}]}
I made my nested collection as:
string dataCollection2 = "{ \"categories\": [ {\"dataid\" : \"11\" , \"dataname\" : \"data1\" , \"datalanguage\" : \"en\" , \"datatype\" : \"type1\" ," +
"\"content\" : \"content1\" , \"tags\" : [{\"myid\" : \"11\" , \"tagid\" : 10 , \"tagname\" : \"tag1\" }] }" +
" , {\"dataid\" : \"22\" , \"dataname\" : \"data2\" , \"datalanguage\" : \"en\" , \"datatype\" : \"type2\" ," +
"\"content\" : \"content2\" , \"tags\" : [{\"myid\" : \"22\" , \"tagid\" : 20 , \"tagname\" : \"tag2\" }] } ] }";
var obj1 = JValue.Parse(#"'" + dataCollection2 + "'");
I imported my json to http://jsonlint,com and I got it is validated:
{
"categories": [
{
"dataid": 11,
"dataname": "data1",
"datalanguage": "en",
"datatype": "type1",
"content": "content1",
"tags": [
{
"myid": 11,
"tagid": 10,
"tagname": "tag1"
}
]
},
{
"dataid": 22,
"dataname": "data2",
"datalanguage": "en",
"datatype": "type2",
"content": "content2",
"tags": [
{
"myid": 22,
"tagid": 20,
"tagname": "tag2"
}
]
}
]}
The fundamental problem with the string you are passing to the REST API is that you are not passing a legal Cypher query. Cypher property "maps", which look a bit like JSON, are NOT JSON.
In your case, the important difference is that property names must NOT be delimited by double-quotes. Only string property values can be delimited by double-quotes.
So, categories, dataId, dataName, etc., must not be surrounded by double-quotes.
You also have a typo near the end of the query. [r2:tagged { Freq : 12 ] should be [r2:tagged { Freq : 12} ].
For Adding nested collection to neo4j:
Firstly: For having right input to neo4j as parameter I must remove "{
"categories": [ ] }" from the first and the end of json.
Secondly: I should put this json as parameter to statement
Thirdly: I have to use two "UNWIND and WITH" (instead of using foreach) for separating each row from collection either for parent or for child.
"Foreach" DOES similar to "UNWIND and WITH".
My final collection and query are:
Collection:
{"id" : 1, "name" : "Data1", "language" : "en", "tags": {"id" : 11, "name": "tag 11" } } , {"id" : 2, "name": "Data2" , "tags": [ {"id" : 33, "name": "tag 33"} , {"id" : 44, "name": "tag44"} ] }
Query:
{ "statements": [ { "statement": " UNWIND { datas } AS data MERGE (p:Person { name : 'God' , lastname : 'God' } ) ON CREATE SET p.id =2 MERGE (d:Data {name: data.name}) ON CREATE SET d.id = data.id , d.language = data.language MERGE (p)-[r:owner]->(d) WITH d, data.tags AS mytags UNWIND mytags AS mytag MERGE (t:Tag {name: mytag.name}) ON CREATE SET t.id = mytag.id MERGE (d)-[r2:tagged { Freq : 12 } ]->(t) " , "parameters": { "datas" : [{"id" : 1, "name" : "Data1", "language" : "en", "tags": {"id" : 11, "name": "tag 11" } } , {"id" : 2, "name": "Data2" , "tags": [ {"id" : 33, "name": "tag 33"} , {"id" : 44, "name": "tag44"} ] }] } } ] }

MongoDB/Mongoid: Can one query for ObjectID in embedded documents?

For the record, I'm a bit of a newbie when it comes to Rails and MongoDB.
I'm using Rails+Mongoid+MongoDB to build an app and I've noticed that Mongoid adds ObjectID to embedded documents for some reason.
Is there any way to query all documents in a collection by ObjectID both the main documents and nested ones?
If I run this command
db.programs.findOne( { _id: ObjectId( "4d1a035cfa87b171e9000002" ) } )
I get these results which is normal since I'm querying for the ObjectID at root level.
{
"_id" : ObjectId("4d1a035cfa87b171e9000002"),
"created_at" : "Tue Dec 28 2010 00:00:00 GMT+0000 (GMT)",
"name" : "program",
"routines" : [
{
"name" : "Day 1",
"_id" : ObjectId("4d1a7689fa87b17f50000020")
},
{
"name" : "Day 2",
"_id" : ObjectId("4d1a7695fa87b17f50000022")
},
{
"name" : "Day 3",
"_id" : ObjectId("4d1a76acfa87b17f50000024")
},
{
"name" : "Day 4",
"_id" : ObjectId("4d1a76ecfa87b17f50000026")
},
{
"name" : "Day 5",
"_id" : ObjectId("4d1a7708fa87b17f50000028")
},
{
"name" : "Day 6",
"_id" : ObjectId("4d1a7713fa87b17f5000002a")
},
{
"name" : "Day 7",
"_id" : ObjectId("4d1a7721fa87b17f5000002c")
}
],
"user_id" : ObjectId("4d190cdbfa87b15c2900000a")
}
Now if I try to query with an ObjectID with one of the embedded document (routines) I get null like so.
db.programs.findOne( { _id: ObjectId( "4d1a7689fa87b17f50000020" ) } )
null
I know one can query embedded objects like so
db.postings.find( { "author.name" : "joe" } );
but that seems a bit redundant if you get passed an ObjectID of some sort and want to find in what document that ObjectID resides.
So I guess my question is this...
Is it possible, with some method I'm not familiar with, to query by ObjectID and search the ObjectID's in the embedded documents?
Thanks.
You can't query ObjectIDs globally like that. You would have to do
db.programs.find({"routines._id": ObjectId("4d1a7689fa87b17f50000020")})
no, you can search only by field like { "routines._id" : ObjectId("4d1a7689fa87b17f50000020")}
If you want to get the matched sub-document only you can use $elemMatch with '$' operator like below:
db.programs.find({"_id" : ObjectId("4d1a035cfa87b171e9000002"),
routines:{$elemMatch:{"_id" : ObjectId("4d1a7689fa87b17f50000020")}}},{"routines.$":1})
It will return you only that matched sub-document instead of the complete sub-document.

Resources