I am pretty new to programming, so I count on your kindness.
Is it possible to send other types than Strings in FCM data message payload, like bool, List or even a documentSnapshot?
If you look at the reference documentation for message.data it is defined as:
data
map (key: string, value: string)
Input only. Arbitrary key/value payload. The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm").
An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
So it is a flat list of key value pairs, where both key and value are strings. If course you can store any data you want in that value, as long as you encode/decode it as a string.
Related
I have a document with a map in it like so:
keys: {
value1: true
value2: true
value3: true
}
I want to allow a user to read that document if any values in a separate document's array match any one of the map keys. The external document is setup like this:
values: [
0: value1,
1: value5,
2: value6,
]
Since the external document array contains "value1" and it matches the key "value1" in the "keys" map, it should allow the read.
I know I can retrieve the external document array using get(/databases/$(database)/documents/myCollection/myDoc).data.values;
But I do not know how to make the comparison properly.
To check if a map has any key that exists in an array:
theMap.keys().hasAny(theArray)
Note that this doesn't care at all what the value is for each key. It's just checking the existence of that key in the map.
So the whole rule would look something like this:
allow read: if resource.data.keys.keys().hasAny(get(...).data.values);
I suggest reviewing the API documentation for Map and List to see other operations.
I have the structure like,
select to_json('[{
"11111":
{
"Number":{"11111"},
"createdTime":"2018-06-25 10:30:11.047 +0530",
"errorMessage":"invalid"
}
}]')
If I try to convert to json structure, I am getting the following error:
ERROR: could not determine polymorphic type because input has type unknown
I need to get a valid json format.
Thanks..
to_json is used to convert e.g. a record or other values that are not a JSON value to proper a JSON value.
You apparently want to use a string value as a JSON.
In order to be able to do that, you need to supply valid JSON. The part "Number":{"11111"} is however invalid JSON, you need to remove the curly braces.
select '[{
"11111":
{
"Number": "11111",
"createdTime":"2018-06-25 10:30:11.047 +0530",
"errorMessage":"invalid"
}
}]'::json
But why are you using a JSON array if you only have a single value? From what you have shown a single JSON value would make more sense:
select '{
"11111":
{
"Number": "11111",
"createdTime":"2018-06-25 10:30:11.047 +0530",
"errorMessage":"invalid"
}
}'::json
I m in the process of creating application where my back end is in go lang and database is mongoDB. My problem is that i have a map in my struct declared like
Data struct {
data map[interface{}]interface{}
}
after adding values in to this like
var data Data
data["us"]="country"
data[2]="number"
data["mother"]="son"
I m inserting it like
c.Insert(&data)
When i insert this i m losing my key and can only see the values...
{
"_id" : Object Id("57e8d9048c1c6f751ccfaf50"),
"data" : {
"<interface {} Value>" : "country",
"<interface {} Value>" : "number",
"<interface {} Value>" : "son"
},
}
May i know any way possible to use interface and get both key and values in my mongoDB. Thanks....
You can use nothing but string as key in MongoDB documents. Even if you would define your Data structure as map[int]interface{} Mongo (don't know if mgo will convert types) wouldn't allow you to insert this object into the database. Actually, you can use nothing but string as JSON key at all as this wouldn't be JSON (try in your browser console the next code JSON.parse('{2:"number"}')).
So define your Data as bson.M (shortcut for map[string]interface{}) and use strconv package to convert your numbers into strings.
But I guess you must look at arrays/slices, as only one reason why someone may need to have numbers as keys in JSON is iterations through these fields in future. And for iterations we use arrays.
Update: just checked how mgo deals with map[int]interface{}. It inserts into DB entry like {"<int Value>" : "hello"}. Where <int Value> is not number but actually string <int Value>
Please help me find a database solution.
Here is the main requirement: One of the columns (the data column) holds a JSON data object which has to be easily searched.
Database row fields:
source (string)
action (string)
description (string)
timestamp (epoch timestamp)
data (can be anything but most likely JSON object or a string)
The nature/schema of this JSON object is unknown (e.g. it can be 1 level deep or 3). The important thing is that tree of the object can be searched.
One possible object:
{
"things": [
{
"ip": "123.13.3.3.",
"sn": "ADF"
},
{
"ip": "123.13.3.3.",
"sn": "ABC"
}
]
}
Another possible object:
{
"ip": "123.13.3.3.",
"sn": "ABC"
}
Example: I want to return all the rows where the data column has a JSON object that has the key/value pair of "SN": "ABC" somewhere in its tree.
Additional Requirements:
Low overhead and/or simple to set up
This database will not be getting hundreds/thousands/millions of hits per minute (now or ever)
Python and/or PHP hooks
I am faced with a problem where I am not sure which path to take. So I am asking it here. I have an application where there can be products and there can be metadata for a product. These metadata can be created and deleted from the front end. So let's say, today a each product has two meta data (e.g. Name, Price) then tomorrow it can be three, four or more or even less than two. So this is dynamic. I am trying to represent the data as follows
Product =
{
"_id": mongo
"Name": string
"Description": string
"BasePrice": number
"CreatedBy": user mongo _id
"CreatedAt": timestamp
"ModifiedAt": timestamp
"MetaData": BSON object (having all the keys from ProductMetadata collection and their values. e.g. {"Category": "table ware", "Material": "oak wood, copper", "Length": 5.6})
}
ProductMetadata =
{
"_id": mongo
"Name": string (e.g. - "Category" or "Material" or "Height")
"Type": string (indicating what kind of value it can hold like string/integer/array. e.g. - "string")
"CreatedAt": timestamp
"ModifiedAt": timestamp
}
As you can see this is a pure dynamic situation so having a structure at the code level which represent the model is impossible.
My problem is, how do I implement such a thing using mgo and Go lang? If I need to use reflection then can some one please point me towards a good blog/tutorial where I can get a little bit more info. Or if you think that there is a fundamental problem in the approach of modeling the data then please correct me so that it can be easily implemented using Go.
In Python, it would not be a problem to implement this. I know that. But I am confused about the Go implementation.
Please help.
Thanks in advance
If Keys for metadata are unique, why not just use a map.
meaning your Product struct looks like:
struct Product {
ID bson.ObjectId `bson:"_id,omitempty"`
Name string
Description string
... omitted other fields ...
MetaData map[string]map[string]interface{} // map of string -> map of string -> anything
}
If you can have more than one instance of a given meta data, ie: 2 categories, use a list:
struct Product {
ID bson.ObjectId `bson:"_id,omitempty"`
Name string
Description string
... omitted other fields ...
MetaData []map[string]interface{} // list of maps of string -> anything
}