how to store url on mongoDB? - mongodb

i want to know what its the correct type to store an image url on mongoDB
i try this using a type: string, but doesn`t work, when is saved on the data base does not appear nothin like a string, instead of that it shows : url: "false".
i need this to save the url on mongodb and upload the images on another platform.
Url:{
type:String,
default:false
},
after of define this on my backend, i sent the argument whit an url on POSTMAN and this was the result on mongoDB compass.
url:"false"

Try matching your key you are sending from frontend "Url" or "url" and send it in string format from postman
This should work Url:{ type:String, default:"" }

Related

AWS Api Gateway Documentation - cant create schema

Today i got into swagger and swagger-ui to create the documentation of our API.
We are using AWS API Gateway with a Lambda function, since AWS is comming with an in-built option for documentation we are going with it.
Sadly, I am pretty limited with this option or I am doing it wrong.
As an example
responses:
'200':
description: 200 response
schema:
$ref: '#/definitions/Empty'
I canĀ“t create an alternative schema, nor im able to edit the existing /Empty schema.
Is there a solution for my problem?
For example
... to not use an schema and just write the whole response in there?
... to show me how to create an alternative schema?
EDIT
For me it seems like an AWS problem, not my swagger file in generall. If someone reads over this i added more informations.
It doesnt matter if i use "create Documetation Part" --> Type = Response (Body) or i go to Ressources --> Method which i want to set the Response (Body) --> Method Response and set the Respone Body to an Modell.
My Modell looks like this
{
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description" : "Example Promotion",
"title" : "Promotion",
"type" : "object",
"properties" : {
"Status" : { "type" : "string"}
}
}
}
It gives me no error, but if i go to "Publish Documentation" it seems to no put the Respone (Body) i set into the swagger.json on the Method Response part, nor on the Defenitions at the end of the file and set the schema path right.
I found it easier to not use $ref when I was starting out. After you have the knack how to write requests or response definitions, you can easily transition to referencing schemas using $ref.
What comes after schema statement? That depends on what you expect to be returned -- text, an array, a JSON object, or an array of JSON objects, etc. Typically it's the later two. So here is an example of each.
schema:
type: object
description: This is a JSON object
properties:
fullName:
type: string
age:
type: number
which defines: { fullName: "Jane Smith", age: 30 }
schema:
type: array
description: This is an array of JSON object
items:
type: object
properties:
carMake:
type: string
carModel:
type: string
which defines: [{ carMake: "Ford", carModel: "Mustang" } ... ]
Clone github's swagger-ui onto your computer and run it as a local server. Or you have free use of the SwaggerHub if you don't mind the API definition to be public (or, after a trial period, pay for your APIs to be private).
The specification has changed over the years, so its important to know whether you are dealing with swagger v2 or openapi v3. www.swagger.io has a good multi-page tutorial. And you can find several public API examples at the SwaggerHub website. I do not work for Smartbear, the originators of both the original swagger spec and swaggerhub tooling, but I've found them to be very helpful in the past. Some of their staff monitor this website and answer questions.
Good luck!

Convert MongoDB Find() return information to String with PyMongo

I am trying to connect to my Twitter application by fetching the consumer key and access token from a MongoDatabase. I'm relatively new to MongoDB and am still trying to get a handle on things. I need the data as a string, but it's being returned as a cursor. I understand that what I have so far won't be the exact value im looking for, but rather something like
{"value" : "ggggktjjjfr4kf0k04kf0rkforvo"}
but if I could at least get this as a string I could begin to decode it. Any advice would be appreciated.
consumer_key = collection_Authentication.find({"name":"consumer_key"}, {"_id":0, "value":1})
consumer_secret=collection_Authentication.find({"name":"consumer_secret"}, {"_id":0, "value":1})
access_token = collection_Authentication.find({"name":"access_token"}, {"_id":0, "value":1})
access_secret = collection_Authentication.find({"name":"access_secret"}, {"_id":0, "value":1})
Something like:
consumer_key = collection_Authentication.find_one({"name":"consumer_key"})["value"]
Use find_one to get the document immediately. In Python the document is represented as a dict, so retrieve the string by its field name, "value", using brackets: ["value"].

How to send POST requests with array properties (Ionic 2 HTTP plugin)?

In one of my Ionic 2 projects I need to send a POST request to a server with a JSON body that looks like this:
var body = { "prop" : 1,
"prop2" : "Test",
"prop3": [{ "id" : "1", "qty": 1, "details": "Test" }]
}
I am using the following code to call the server using the native HTTP plugin (1.2.0) in Android:
http.post(url, body, {}).then(function() { ... })
But my server is receiving the following:
{ "prop" : 1,
"prop2" : "Test",
"prop3": "[{ \"id\" : \"1\", \"qty\": 1, \"details\": \"Test\" }]"
}
As you can see, the array property "prop3" is being turned into a string, so my server is failing to parse it because it's expecting an array, not a string.
One of the things I could do is to change the server side code to parse this string back into an array (but that would be far from ideal). The other thing I could do is to parse the JSON object manually with JSON.stringify.
So, is this just a bug in the plugin or am I missing something here?
Native HTTP plugin
Try set http.setDataSerializer("json");
And send data as usual: http.post(url, body, {})
Then http plugin will send data with application/json content type and support deep structure of json, as stated in the documentation:
https://github.com/silkimen/cordova-plugin-advanced-http#setdataserializer
So, after taking a look at the plugin's source code (the Java one, I'm testing my application in Android) it seems that I won't be able to use the plugin as is (I would need to modify it). What I found was this:
In CordovaHttpPost.java, the body of the request is sent as Form data (simple key-values).
request.form(this.getParams()); //Map<?, ?>
That's why my array property is converted into a string (and any other complex object for that matter)
TL;DR this plugin is only useful to send simple JSON key-value objects (no nesting, no complex objects, no arrays, etc.).

How to pass MongoDb Json value to KendoUI grid using webservice method

I'm new to KendoUI, trying to populate a KendoUI grid with JSON data which is fetched from mongoDB as BsonDocument lsit and returned as JSON string,
var ds = new kendo.data.DataSource({
transport: {
read: {
url: "WebService.asmx/GetJson",
dataType: "json",
data: {
q: "data"
}
}
},
schema: {
data: "statuses"
}
});
$("#grid").kendoGrid({
dataSource: ds
});
I tried this one, grid is not binding to me, was I'm doing wrong, how to bind my data to grid, pls help me waiting for kind reply.
note: Grid should not be defined structure with column fields, based on Json string grid structure has to changed.
I think you're probably trying to do too many things at once if you're new to KendoUI. Try just binding the grid to some static data (hard coded into the web page) that looks exactly like the data from MongoDB first... You should be able to extract this from MongoDB easily enough using something like MongoVue.
Once you're sure the data itself is in the right format and the grid is configured to use this properly, then try setting up a remote url or web service to fetch the data and make sure that the data retrieved from the remote url is what you're expecting.
Finally, when you have both of those pieces of the puzzle in place, you should look at hooking the KendoUI grid up to the remote web service.

facebook, how to send tracking info for the user inside data?

i am using this example to send messages to my friends.
the problem i get into is how do i use the data property to add some tracking info.
I would like to pass a var $test and then be able to read it in a json format, or even an array.
In other words, I would like to pass a var when i send the message and when they accept it and it redirect them to the canvas, i would like to be able to grab it from somewhere:
ex:
"data":[
{
"id":"167548189960088",
"application":{
"name":"Cat's Test Site",
"id":"314268391344"
},
"to":{
"name":"Cissy Lim",
"id":"100001147247007"
},
"data":"'here is my var'",
"message":"'INSERT_UT8_STRING_MSG'",
"created_time":"2011-02-16T08:37:02+0000"
},
Thanks
The "data" parameter currently only supports a string. Very annoying since Facebook seems to support json objects everywhere else. You could put a "json string" there and then eval that to a json object when you want to read it.